Solved QCoreApplication::sendEvent issue
-
Hello!
I have the application which uses singleton pattern, and when emiting signal from the main window to this singleton class it displays the following issue:
ASSERT failure in QCoreApplication::sendEvent: "Cannot send events to objects owned by a different thread. Current thread 0x0x199953e0f30. Receiver 'qt_scrollarea_viewport' (of type 'QWidget') was created in thread 0x0x19990c6b7d0", file kernel\qcoreapplication.cpp, line 563
The application contains few
QTreeWidgets
and buttons. When I select theQTreeWidgetItem
and click a button it emits the appropriate signal.Example code:
connect(this, &MainWindow::mySignal, &Test::instance(), &Test::doSomething); emit mySignal(ui->treeWidget->currentItem()->text(0), ui->treeWidget->currentItem()->text(1), ui->treeWidget->currentItem()->text(5), ui->treeWidget->currentItem()->text(2), ui->treeWidget->currentItem()->text(7), ui->treeWidget->currentItem()->text(1), true, true);
Also, this issue only appear in the
Debug
mode only. In theRelease
mode it works well. I useQt 5.9.8 LTS
. Any ideas how to fix it? Thanks. -
Ok. I have found the problem. The issue is with
Wlan API callback
function, for example:When I check:
case wlan_notification_acm_connection_start: if (wlanNotificationData->dwDataSize != sizeof(WLAN_CONNECTION_NOTIFICATION_DATA)) { emit instance().notifDataSizeFailed(); break; } emit instance().apConnecting(); break;
it emits signal and sets the button text to "Connecting". This code for some reason lead to
ASSERT failure in QCoreApplication::sendEvent
issue only in theDebug
mode. -
I can add some checks for this code:
#ifndef QT_DEBUG #endif
But I think there is a better solution. Thanks in advance for your help.
-
During some code investigation, I found that
break;
actually breaks the application event loop and can not return to it when newWlan
state is registered, theWlan API callback
function receives different states.For example:
- It gets the
wlan_notification_acm_connection_start
state - Then it emits signal to displays button text, then it breaks from
switch
- New state is registered from the
Wlan callback
function, for example,wlan_notification_acm_connection_complete
, but it can not return to this event anymore because it made a break early (it broke not only from the switch but also from this event loop). Also, possible to say it broke from theconnect
.
That is why, I changed it to
if/else
:if (wlanNotificationData->NotificationCode == wlan_notification_acm_connection_start) { if (wlanNotificationData->dwDataSize != sizeof(WLAN_CONNECTION_NOTIFICATION_DATA)) { emit instance().notifDataSizeFailed(); return; } emit instance().apConnecting(); } else if (wlanNotificationData->NotificationCode == wlan_notification_acm_connection_complete) { ..... }
Now it works well in
Debug/Release
modes. The issue is resolved. - It gets the