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. emit one signal for two objects
Forum Update on Tuesday, May 27th 2025

emit one signal for two objects

Scheduled Pinned Locked Moved General and Desktop
signal & slot
4 Posts 4 Posters 1.4k Views 1 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.
  • L Offline
    L Offline
    LeaA
    wrote on last edited by
    #1

    hi,

    we are trying to emit signal that will execute slot. the signal emitted once but the slot need to be execute twice for two different objects.

    here is the code of connecting::

    for(int i=0;i< MSStorageData.size();i++)
    {
    for(int p=0;p<processingVector.size();p++)
    {
    connect(MSStorageData.at(i).get(),SIGNAL(arrivedNewMs()),
    processingVector.at(p).get(),SLOT(newMS()),Qt::DirectConnection);

        }
    

    }

    and the emit only one time needs to execute the newMS slot of the two objects in the processingVector.

    the program crashed..
    there is someone who know what can be the problem?

    tnx!

    CKurduC 1 Reply Last reply
    0
    • H Offline
      H Offline
      Huulivoide
      wrote on last edited by
      #2

      I don't understand what the problem is.
      You can connect as many different objects to act on the
      specific signal as you like. You just connect all the objects
      you want to receive the signal to the object.

      connect(sender, &Sender::mySignal, receiver1, &Receiver::mySlot);
      connect(sender, &Sender::mySignal, reiceiver2, &Receiver::mySlot);
      
      sender.emitMySignal();
      
      1 Reply Last reply
      0
      • V Offline
        V Offline
        Vaquita Tim
        wrote on last edited by
        #3

        Right, agreed - a signal can be connected to as many slots as you like. It should work. Probably your crash is due to something else.
        Maybe the problem is in your slot function - n.b. the order in which the slot functions are called in not controlled (could be in any order, and could change from one version to another).
        Or maybe you are changing your arrays, thus invalidating the pointers to your receiver objects. If you do change your arrays, I recommend calling "disconnect" first, before changing them, then calling connect again.
        Nevertheless, I generally recommend you simplify everything until you get something working (e.g. use a couple of fixed objects rather than arrays) then make it more complicated (until it breaks :-) !

        1 Reply Last reply
        0
        • L LeaA

          hi,

          we are trying to emit signal that will execute slot. the signal emitted once but the slot need to be execute twice for two different objects.

          here is the code of connecting::

          for(int i=0;i< MSStorageData.size();i++)
          {
          for(int p=0;p<processingVector.size();p++)
          {
          connect(MSStorageData.at(i).get(),SIGNAL(arrivedNewMs()),
          processingVector.at(p).get(),SLOT(newMS()),Qt::DirectConnection);

              }
          

          }

          and the emit only one time needs to execute the newMS slot of the two objects in the processingVector.

          the program crashed..
          there is someone who know what can be the problem?

          tnx!

          CKurduC Offline
          CKurduC Offline
          CKurdu
          wrote on last edited by
          #4

          @LeaA
          Are you programming multi thread or single thread. You are using Qt::DirectConnection parameter. If your program is multi thread , it can be reason for crach.

          If you are not programming multi thread, can you sure that every pointer is not "null pointer" in your connect function.

          You reap what you sow it

          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