Does connection of SLOT and SIGNAL from different threads must be made in the sender or in the reciever thread ?



  • Does connection of SLOT and SIGNAL from different threads must be made in the sender or in the reciever thread ?
    Also, Does the connection and disconnection must be made in the same thread ?


  • Moderators

    Hi,

    @aabc said:

    Does connection of SLOT and SIGNAL from different threads must be made in the sender or in the reciever thread ?
    Also, Does the connection and disconnection must be made in the same thread ?

    It doesn't matter, because connect() and disconnect() are thread-safe.

    Just make sure your connection uses Qt::AutoConnection or Qt::QueuedConnection, so that the slot runs in the receiver's thread.



  • Hi,

    from technical point of view @JKSH is right.
    From design point of view senders shouldn't know about objects connected to their signals: a signal is simply an indication of something is changed in the sender internal state and then is incorrect make the connection in the sender code. (doing this the sender will be tightly coupled with the receiver)

    SIGNALS/SLOTS are designed to avoid (or reduce as much as possible) the coupling from senders and receivers


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.