Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
What is the difference between macros Q_INVOKABLE and Q_PROPERTY?
Ronak5 last edited by
I know the basic usage of both the macros. I've using Q_PROPERTY to access the cpp objects in qml.
Lately I came across Q_INVOKABLE also and I read it can used by qt moc to access member functions in qml.
I'm bit confused regarding on what basis and how do I decide which macro to be used and when? Thanks.
I'm bit confused regarding on what basis and how do I decide which macro to be used and when?
Q_PROPERTY is a property (with a getter, maybe a setter, notifier signal, etc) which enables you bindings etc.
Q_INVOKABLE simply marks a method to be callable via moc (and thus also via QML for example), nothing more. Similar to slots for example.
Pablo J. Rogina last edited by
Q_PROPERTY(Priority priority READ priority WRITE setPriority NOTIFY priorityChanged)
And for Q_INVOKABLE and following with that example, you could imagine a method applyPriority for example so if you apply Q_INVOKABLE to it, it could be called from some other C++ classes or even from QML as mentioned before.