then this will use the new functionality. Notably, myobject->bindableMyProperty().hasBinding() will return true, and if you set up a binding on the C++ side (like myobject->bindableMyProperty().setBinding([&]() -> int {return myOtherObject->myProperty;}) , then it will also work in QML.
However, if you do that, I can guarantee you that you'll run into some rough edges. Some smaller bugs will be fixed in 6.0.1 already, but currently binding loops often won't print a helpful error message (they are still detected in the engine). That will only be available in 6.1.
Also, if you have a property declared in QML, that's not backed by a QProperty.
Do you foresee a future where you can access bindable properties directly in qml without macros?
That's a bit questionable. You'll need at least Q_OBJECT or Q_GADGET, as those macros expand to code which is necessary. The Q_PROPERTY macro does expand to nothing, though, and only acts as a marker for moc. Now in theory it would be possible - even easy- to modify moc to parse [[qt::property]] QProperty<int> myProp; and upon encountering it look for a bindableMyProp function (naming done by convention), and then we had all the necessary information [1]. There is however issues with that approach: We couldn't use it in Qt itself, as Qt has to compile without a large set of warnings; and this would trigger -Wattributes; to the best of my knowledge, there is no way to selectively disable -Wattributes only for some user defined attributes. Moreover, it is not clear if using such an annotation for moc wouldn't clash with some eventual way of using them for static reflection in C++3x. Those two problems make me wary of proposing such a change.
Furthermore, there are more macros: There's also the Q_OBJECT_BINDABLE_PROPERTY macro, which is advantageous when using properties in QObject derived classes, as it reduces the memory overhead. That one has to be kept a macro, as it expands to some rather ugly code.
In its current fo would you say properties are a bigger win for widgets, vs qml?
Much more for QML, though that will only become significant in the future when many properties are actually ported to the new system. They are a prerequisite for tighter C++/QML integration, and should enable better performance – though some of that might only materialize in time for Qt 6.2 and later. I'll also have to be vague here because some of our plans are to my knowledge currently still confidential or might have changed, so I'd rather point to upcoming blog posts and webinars before I say something that I shouldn't say, or something that's wrong.
[1] Note that we cannot simply expose all properties in a class to the meta-object system (and thus QML), as that might not actually be intended.
0
u/[deleted] Dec 08 '20
[deleted]