Unsolved how do i UpdateUI in a Callback which is non-mainThread & non-QtThread?
-
@opengpu can you please provide a bit more information? how does the callbacks function signature look like?
-
@aha_1980 just a callback funtion in windows dev, but that callback is returned from a 3rdParty DLL which use COM
-
-
@aha_1980
WINAPI Callback(const Data& data)
{
//here is not mainThread; so i have to pass the data by value to the slot which is in mainThread; or i use mutex & save data to m_data, and then in slot mainThread getData also with mutex protect thread-safety
} -
is this a good way to emit signal in the non-thread non-qt Callback function?
WINAPI Callback(const Data& data) {//here is not mainThread; so i have to pass the data by value to the slot which is in mainThread; or i use mutex & save data to m_data, and then in slot mainThread getData also with mutex protect thread-safety emit g_qtObj->mySignal(); } class QtObj : public QObject { Q_OBJECT signals: void mySignal(); } QtObj g_obj; QtObj* g_qtObj = &g_obj;
-
-
@opengpu said in how do i UpdateUI in a Callback which is non-mainThread & non-QtThread?:
g_qtObj->emit mySignal();
should be
g_qtObj->mySignal();
-
@jsulm thanks
-
@SGaist ```
WINAPI Callback(const Data& data)
{//here is not mainThread; so i have to pass the data by value to the slot which is in mainThread; or i use mutex & save data to m_data, and then in slot mainThread getData also with mutex protect thread-safety
//emit g_qtObj->mySignal();
QMetaObject::invokeMethod(g_pQtMainWindow, slotDoSth, Qt::QueuedConnection);
}like this? use invokeMethod instead of emit signal ?
-
Why do you have a global Qt object ?
What makes you define yourCallback
method like that ? -
why QMetaObject::invokeMethod pass custom-type called Twice custom-type's copy constructor...
https://forum.qt.io/topic/102915/qmetaobject-invokemethod-pass-custom-type-called-twice-custom-type-s-copy-constructor