Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

When to use Qt::DirectConnection and QueuedConnection



  • Hi,

    When should we use Direct Connection and Queued Connection while writing a connect Statement.

    The Signal in the connect statement is in a different thread and the Slot emits a signal that needs to update a value in the UI(QML).

    So how do we decide as to which is the best connection type to use.

    Thank You


  • Moderators

    If it is in a different thread, you should use QueuedConnection for sure. This way you can be certain no thread synchronization issues occur.

    Or, if you leave connection type argument empty, Qt will choose the right type automatically for you (queued for threaded connections, direct otherwise).

    You can also use QueuedConnection in single-thread connections to delay slot execution a bit, allow the event loop to spin etc.

    In short:

    • direct connection is the same as direct function call - it is called immediately and in the same thread
    • queued connection is inserted into event loop and will be called "some time in the future, by receiving thread". Where "some time" is usually "very quickly"

Log in to reply