Details
-
Suggestion
-
Resolution: Won't Do
-
Not Evaluated
-
None
-
5.12.3
-
None
-
Kubutnu 18.04 64bit
Description
Hi
Since C+98 is there posible to create true properties in pure C+ (like Delphi or C++ Builder have). Yesterday I wrote bridge from C++ to Qml for my sily Class with just 10 variables - I need to add properties in order to make variables accessible from Qml - when I done I have 300 lines of code - so: is it realy simplier code in Qml than in pure C++?!? But never mind.
Today I wrote my Property class (with some basic tests). Now I share it on git hub:
https://github.com/SzykCech4/EnergoKodProperty/blob/master/Include/EnergoKodProperty/Property.h
whole project is there:
https://github.com/SzykCech4/EnergoKodProperty.git
Property is created as follow:
Property<WithProperties, std::string> mStringProperty = Property<WithProperties, std::string>(this, &WithProperties::getString, &WithProperties::setString, &WithProperties::notifyString);
And can be accesible like this:
lObject.mStringProperty = "Takie coś!";
or:
if(lObject.mStringProperty == "Takie coś!") std::cout << "string asingment OK!" << std::endl;
Then data is fetched, writalbe and notify by functions pased in constructor (similiary to current Qt property system). The advantage is that you can use this property like any other variable (beside anoynig cast for some types of data).
Basically it works, but with some strange limits: int type is correctly, automatically cast from Property template (at least for my test cases), but std::string fails for its own operators (tested: +=, and <<).
So what about refactoring C++ property system with advent of Qt6? Real properties by value instead by explicit functions will be great progress for any Qt programmers) not found.
best regards
Szyk Cech