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. Signals, Threads and the Event Queue
Forum Updated to NodeBB v4.3 + New Features

Signals, Threads and the Event Queue

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 1.0k Views 2 Watching
  • 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.
  • D Offline
    D Offline
    DalePennington
    wrote on last edited by
    #1

    Folks,

    We have an app acting strangely, so we are looking at all possible avenues that might be the cause.
    With regard to the question here, we have an object, created on the main thread, that registers a call back with a third party communications library that invokes the callback on its own thread. We take the incoming message, put it in a QQueue (protected by a QMutex), and emit a signal. The slot the signal is associated with is in the same object, but should be being called in the main Qt thread.
    The questions are several. First, is the signal passed to the main thread via the Qt Event Mechanism ? I known the documentation says that QueuedConnections process when the receiving threads Event Dispatcher runs, but I am trying to confirm details. I am also assuming from the documentation that the method is thread-safe.
    Second, with regards to the queued events, is there a limit to the Qt Event Queue size ? If so, what happens when it overflows ? Finally is there a way to see how many pending events their are ?
    I doubt this is what is causing the issue, but we are trying to eliminate all possible issues.

    Thanks,
    Dale Pennington

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Why does the slot need to be called in main thread ? Is it changing GUI elements ? How exactly to you emit your signal ?

      The slot shall be called in whichever thread the target object has affinity with.

      For queued connections, yes the event system is used to pass from on thread to another. More details here.

      I don't know whether there's an upper limit on the event queue but if you manage to overload it, then you may have a performance hit somewhere you have to find, a design issue or a need for a more powerful machine. The last one is the less likely usually.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • D Offline
        D Offline
        DalePennington
        wrote on last edited by
        #3

        The slot is in the main thread because it does change graphical elements.

        Basically we have a callback function that looks like this

        void CommClass::Callback(Data data)
        {
            dataMutex.lock();
            dataQueue.enqueue(data);
           dataMutex.unlock();
           emit DataReceived();
        }
        

        DataRecieved is tied to slot HandleData

        void CommClass::HandleData
        {
            while(1)
            {
                dataMutex.lock();
                if( dataQueue.empty() )
                {
                    dataMutex.unlock();
                    return;
                }
        
                Data localData = dataQueue.dequeue();
                dataMutex.unlock();
        
                //  Use data here to update display elements.
            }
        }
        

        We are getting a backup to processing the data due to other GUI interfaces creating a backlog, so boss was worried about possibly overflowing the Event Queue and that being a possible issue.

        Thanks for the time,
        Dale Pennington

        Christian EhrlicherC 1 Reply Last reply
        0
        • D DalePennington

          The slot is in the main thread because it does change graphical elements.

          Basically we have a callback function that looks like this

          void CommClass::Callback(Data data)
          {
              dataMutex.lock();
              dataQueue.enqueue(data);
             dataMutex.unlock();
             emit DataReceived();
          }
          

          DataRecieved is tied to slot HandleData

          void CommClass::HandleData
          {
              while(1)
              {
                  dataMutex.lock();
                  if( dataQueue.empty() )
                  {
                      dataMutex.unlock();
                      return;
                  }
          
                  Data localData = dataQueue.dequeue();
                  dataMutex.unlock();
          
                  //  Use data here to update display elements.
              }
          }
          

          We are getting a backup to processing the data due to other GUI interfaces creating a backlog, so boss was worried about possibly overflowing the Event Queue and that being a possible issue.

          Thanks for the time,
          Dale Pennington

          Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @DalePennington said in Signals, Threads and the Event Queue:

          while(1)

          This is running in the main thread? How do you break this loop?

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          JonBJ 1 Reply Last reply
          0
          • Christian EhrlicherC Christian Ehrlicher

            @DalePennington said in Signals, Threads and the Event Queue:

            while(1)

            This is running in the main thread? How do you break this loop?

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #5

            @Christian-Ehrlicher said in Signals, Threads and the Event Queue:

            How do you break this loop?

            Well, on his first 5 lines. No data => unlock and return?
            Else he seems to process whole queue from slot.

            Christian EhrlicherC 1 Reply Last reply
            0
            • JonBJ JonB

              @Christian-Ehrlicher said in Signals, Threads and the Event Queue:

              How do you break this loop?

              Well, on his first 5 lines. No data => unlock and return?
              Else he seems to process whole queue from slot.

              Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @JonB said in Signals, Threads and the Event Queue:

              Well, on his first 5 lines. No data => unlock and return?

              Correct, strange logic though :)

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply
              1

              • Login

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