const QObject* overload for QMetaObject::invokeMethod
-
Hi,
How come you get a const QObject pointer to call invokeMethod with ?
-
@SGaist i want to ensure that some member function are called in the thread of the object to avoid data races mostly. I decided to implement a function accepting a function object containing thé code to execute. If the current thread is the object one, il directly invoke the function object with std::invoke. If not, i call the function object on the object context via QMetaObject::invokeMethod.
Some of the function i want to be called on the same thread are getters that I put const by default.
-
@SGaist i want to ensure that some member function are called in the thread of the object to avoid data races mostly. I decided to implement a function accepting a function object containing thé code to execute. If the current thread is the object one, il directly invoke the function object with std::invoke. If not, i call the function object on the object context via QMetaObject::invokeMethod.
Some of the function i want to be called on the same thread are getters that I put const by default.
@Loic-B said in const QObject* overload for QMetaObject::invokeMethod:
Some of the function i want to be called on the same thread are getters that I put const by default.
Then it's not a slot and there is no need that it's called via QMetaMethod.
-
@Loic-B said in const QObject* overload for QMetaObject::invokeMethod:
Some of the function i want to be called on the same thread are getters that I put const by default.
Then it's not a slot and there is no need that it's called via QMetaMethod.
@Christian-Ehrlicher so how can i ensure that without using the QMetaObject::invokeMethod ? By using mutexes ?
-
@Christian-Ehrlicher so how can i ensure that without using the QMetaObject::invokeMethod ? By using mutexes ?
@Loic-B said in const QObject* overload for QMetaObject::invokeMethod:
By using mutexes ?
If you access an object from different threads then you have to apply correct locking. Nothing Qt specific but Qt has a nice page about thread synchronization.