Is Q_INVOKABLE necessary to call a public QObject function from QML in general in Qt5?

I just realized that I can name almost any function of the object that undergoes QML. Now I'm interested in learning about Q_INVOKABLE. Qt5 docs state :

[...] any QML code can access the following members of an instance of a class derived from QObject:

  • The properties

  • Methods (if they are public slots or labeled Q_INVOKABLE)

  • Signals

Starting from Qt5 (in C ++) I can call any public QObject function as a slot, i.e. I don’t need to declare them as a “public slot”. Does this mean that I can name any method from QML? I can not find anything in the docs.

+4
source share
1 answer

Yes, you have to tag your QObject function with Q_INVOKABLE, if not public slot, 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.

+7
source

Source: https://habr.com/ru/post/1628277/


All Articles