Q_INVOKABLE vs SIGNAL/SLOT thread safety
-
I have several methods which are defined as Q_INVOKABLE. One such method is:
Q_INVOKABLE void logError(const QString& msg_in);
This method is called by my QML objects to log error events as suggested above.
The class which defines this method is MainApp. It is running on my QGuiApplication event loop. MainApp also makes calls logError() to log its own error messages. I am trying to determine if the QML calls and my MainApp calls are thread safe, even though I am not explicitly defining a signal/slot connection
Thanks!
-
If you call a
Q_INVOKABLE
method from QML it is called using QMetaObject::invokeMethod behind the scenes. So, it is thread-safe per se. But: Your usual QtQuick stuff lives on the GUI thread and thus, unless you explicitly use other threads, there's no problem anyways.Edit: My original answer was wrong.
-
Hi,
How are you calling that method ?
-
What @Wieland wrote is correct :)
-
If you call a
Q_INVOKABLE
method from QML it is called using QMetaObject::invokeMethod behind the scenes. So, it is thread-safe per se. But: Your usual QtQuick stuff lives on the GUI thread and thus, unless you explicitly use other threads, there's no problem anyways.Edit: My original answer was wrong.