Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QCoreApplication::sendEvent issue
Qt 6.11 is out! See what's new in the release blog

QCoreApplication::sendEvent issue

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 1 Posters 958 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Cobra91151C Offline
    Cobra91151C Offline
    Cobra91151
    wrote on last edited by
    #1

    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 the QTreeWidgetItem 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 the Release mode it works well. I use Qt 5.9.8 LTS. Any ideas how to fix it? Thanks.

    1 Reply Last reply
    0
    • Cobra91151C Offline
      Cobra91151C Offline
      Cobra91151
      wrote on last edited by Cobra91151
      #2

      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 the Debug mode.

      1 Reply Last reply
      0
      • Cobra91151C Offline
        Cobra91151C Offline
        Cobra91151
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • Cobra91151C Offline
          Cobra91151C Offline
          Cobra91151
          wrote on last edited by
          #4

          During some code investigation, I found that break; actually breaks the application event loop and can not return to it when new Wlan state is registered, the Wlan API callback function receives different states.

          For example:

          1. It gets the wlan_notification_acm_connection_start state
          2. Then it emits signal to displays button text, then it breaks from switch
          3. 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 the connect.

          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.

          1 Reply Last reply
          2

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved