I just realized that I can call pretty much any function of an object that is exposed to QML. Now I am curious about Q_INVOKABLE. The Qt5 docs state:
[...] any QML code can access the following members of an instance of a QObject-derived class:
Properties
Methods (providing they are public slots or flagged with Q_INVOKABLE)
Signals
Since Qt5 (In C++) I can invoke any public function of a QObject like a slot, i.e. I do not have to declare them as 'public slot'. Does this mean I can call any method from QML? I cant find anything in the docs.
Yes, you have to mark your function of a QObject with Q_INVOKABLE
unless it's a public slot
in order to be able to call it from QML.
Both Q_INVOKABLE and the slots keyword register your function with Qt meta-system
. The difference is that with Q_INVOKABLE you can return values.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With