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. How deep can signals and slots go? A few fundamental questions about signals and slots...
QtWS25 Last Chance

How deep can signals and slots go? A few fundamental questions about signals and slots...

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 934 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.
  • P Offline
    P Offline
    primem0ver
    wrote on last edited by
    #1

    I have a general question about signals and slots and the way that they are handled. In order for signals to be processed, I assume they need to be attached to a specific thread so that a message loop can register the fact they they have been fired (emitted) and the corresponding slot can be called.

    So how deep can they go?
    Must all signals and slots be "connected" in the base application/loop? Or can one create a signal/slot connection in objects created on the fly?
    If they can be created on the fly in objects other than the object containing the main message loop, how does that connection manager to be embedded in the message loop?

    Mainly... I am trying to understand what things might go wrong when using signals and slots and to make sure that all my signals make it to an event loop somewhere...

    1 Reply Last reply
    0
    • C Offline
      C Offline
      chrisaverage
      wrote on last edited by
      #2

      Signals and slots are not assigned to threads. QObjects that have signals and slots have so called thread affinity. A QObject is by default assigned to the thread it was created in. You can control that using QObject::moveToThread(...).

      Connections don't require active loop at connection time (when you call connect). A loop in the target thread is required at the emission-time (when you call emit someSignal() ) of "queued connections":http://qt-project.org/doc/qt-5/qt.html#ConnectionType-enum. Connections can be created and destroyed anywhere and at any time and don't require any parent object to be made (QObject::connect() is a static method).

      Connections can be made for objects in different threads. There are different types of connection (optionally controlled by the last param of connect() ).

      More on how threading, event loops, and connections work together "can be found here":http://qt-project.org/doc/qt-5/threads-qobject.html and "here":http://qt-project.org/doc/qt-5/qobject.html#thread-affinity

      1 Reply Last reply
      0
      • P Offline
        P Offline
        primem0ver
        wrote on last edited by
        #3

        Thanks! I appreciate the info.

        1 Reply Last reply
        0

        • Login

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