Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. When to use Qt::DirectConnection and QueuedConnection
Forum Updated to NodeBB v4.3 + New Features

When to use Qt::DirectConnection and QueuedConnection

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 2 Posters 6.9k 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.
  • A Offline
    A Offline
    Anita
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      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"

      (Z(:^

      1 Reply Last reply
      4

      • Login

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