I have a following Q_PROPERTYs declared and of course the respective glue code for it.
Q_PROPERTY(bool thisEnabled READ isThisEnabled NOTIFY thisEnabledChanged)
Q_PROPERTY(bool thatEnabled READ isThatEnabled NOTIFY thatEnabledChanged)
Q_PROPERTY(bool somethingEnabled READ isSomethingEnabled NOTIFY somethingEnabledChanged)
Q_PROPERTY(bool somethingElseEnabled READ isSomethingElseEnabled NOTIFY somethingElseEnabledChanged)
Above works great!
Question:
But, these Q_PROPERTYs are part of a class which will add more features in future and hence more Q_PROPERTYs. Please note that all would be of type bool.
Now my concern is that I don't want add 5 more Q_PROPERTYs to 5 more features added. Is there some way I can add a Q_PROPERTY which is checked in QML by passing a Q_ENUM? Something like below?
// QML code
Rectangle {
id: some_rect
visible: cppClass.isEnabled(some_qenum_value)
}
Issue with using a Q_INVOKABLE here:
I know that I could add a Q_INVOKABLE method but if I add a Q_INVOKABLE, I loose the dynamic binding feature of a Q_PROPERTY.
I am using Qt 5.15.9 commercial version.
Flags are the way to go. Since integers are 32-bit, technically, you can use this to store your 4 boolean values and you have the ability to scale up to 32 boolean values:
In QML, you can set the flags property by combining 0, 1 or more flags together with a bitwise | operator. e.g.
Here is a QML for that demonstrates reading, setting, clearing each flag:
Below is another simplified version of the QML without the C++ class. It further illustrates how to read, set, and clear flags from your integer value:
You can Try it Online!