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. [SOLVED] SIGNAL/SLOT cannot work with Qt:QueuedConnection
Forum Update on Monday, May 27th 2025

[SOLVED] SIGNAL/SLOT cannot work with Qt:QueuedConnection

Scheduled Pinned Locked Moved General and Desktop
signal & slotterminalserialportqueuedconnectiothreadthreading
5 Posts 2 Posters 9.6k 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.
  • S Offline
    S Offline
    Sen Li
    wrote on 8 Jun 2015, 18:21 last edited by Sen Li 6 Sept 2015, 18:18
    #1

    Hi,

    I was working on Terminal example of Qt, and encountered a problem that, the SLOT never work once Qt::QueuedConnection added.
    Codes:

    struct Settings {
        QString name;
        qint32 baudRate;
        QString stringBaudRate;
        QSerialPort::DataBits dataBits;
        QString stringDataBits;
        QSerialPort::Parity parity;
        QString stringParity;
        QSerialPort::StopBits stopBits;
        QString stringStopBits;
        QSerialPort::FlowControl flowControl;
        QString stringFlowControl;
        bool localEchoEnabled;
    };
    connect(this, SIGNAL(emitOpenSerialOrder(Settings)), myDefaulSerialObject, SLOT(openSerialPort(Settings)));
    

    The codes above work well with out Qt::QueuedConnection; however, once I add it,

    connect(this, SIGNAL(emitOpenSerialOrder(Settings)), myDefaulSerialObject, SLOT(openSerialPort(Settings)), Qt::QueuedConnection);
    

    the SLOT never work.

    This problem stops me from moving myDefaulSerialObject into a new thread!

    Could anyone tell me how to fix this?
    Thank you!

    1 Reply Last reply
    0
    • L Offline
      L Offline
      Leonardo
      wrote on 8 Jun 2015, 18:39 last edited by
      #2

      Hi. Why should you specify Qt::QueuedConnection? If the object is in another thread, queuing the signals is already the default behavior. Why not let Qt decide? See:

      http://doc.qt.io/qt-5/qt.html#ConnectionType-enum

      Qt::AutoConnection (Default) If the receiver lives in the thread that emits the signal, Qt::DirectConnection is used. Otherwise, Qt::QueuedConnection is used. The connection type is determined when the signal is emitted.

      S 1 Reply Last reply 8 Jun 2015, 18:58
      0
      • L Leonardo
        8 Jun 2015, 18:39

        Hi. Why should you specify Qt::QueuedConnection? If the object is in another thread, queuing the signals is already the default behavior. Why not let Qt decide? See:

        http://doc.qt.io/qt-5/qt.html#ConnectionType-enum

        Qt::AutoConnection (Default) If the receiver lives in the thread that emits the signal, Qt::DirectConnection is used. Otherwise, Qt::QueuedConnection is used. The connection type is determined when the signal is emitted.

        S Offline
        S Offline
        Sen Li
        wrote on 8 Jun 2015, 18:58 last edited by
        #3

        @Leonardo said:

        f the receiver lives in the thread that emits the signal, Qt::DirectConnection is used. Otherwise, Qt::QueuedConnection is used. The connection type is determined when the signal is emitted.

        Hi,

        Glad to see you here!

        Actually, I am confused. The slot should work even if I specify it to be Qt::QueuedConnection.
        Then why it doesn't work?

        Also, whenever I move the object into a new thread,

        mySerialThread = new QThread();
        myDefaulSerialObject->moveToThread(mySerialThread);
        mySerialThread->start();
        

        it doesn't work either even without my specifying of Qt::QueuedConnection.

        This is really weird because all the other SIGNAL/SLOT have no problem with Qt::QueuedConnection, and the only difference is the Structure argument Settings.

        1 Reply Last reply
        0
        • L Offline
          L Offline
          Leonardo
          wrote on 8 Jun 2015, 19:02 last edited by
          #4

          Now that you mentioned it... Again, see:

          http://doc.qt.io/qt-5/qt.html#ConnectionType-enum

          With queued connections, the parameters must be of types that are known to Qt's meta-object system, because Qt needs to copy the arguments to store them in an event behind the scenes.
          ...
          Call qRegisterMetaType() to register the data type before you establish the connection.

          Maybe that's what you're missing.

          S 1 Reply Last reply 8 Jun 2015, 19:08
          1
          • L Leonardo
            8 Jun 2015, 19:02

            Now that you mentioned it... Again, see:

            http://doc.qt.io/qt-5/qt.html#ConnectionType-enum

            With queued connections, the parameters must be of types that are known to Qt's meta-object system, because Qt needs to copy the arguments to store them in an event behind the scenes.
            ...
            Call qRegisterMetaType() to register the data type before you establish the connection.

            Maybe that's what you're missing.

            S Offline
            S Offline
            Sen Li
            wrote on 8 Jun 2015, 19:08 last edited by
            #5

            @Leonardo said:

            nections, the parameters must be of types that are known to Qt's meta-object system, because Qt needs to copy the arguments to store them in an event behind the scenes.
            ...
            Call qRegisterMetaType() to register the data type before you establish the connectio

            Wow, that really helps!

            Thank you so much!

            I will try it right now

            1 Reply Last reply
            0

            4/5

            8 Jun 2015, 19:02

            • Login

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