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. Connect multiple slots to one signal
QtWS25 Last Chance

Connect multiple slots to one signal

Scheduled Pinned Locked Moved Solved QML and Qt Quick
signal&slotqcanbusdevice
10 Posts 3 Posters 6.7k 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.
  • B Offline
    B Offline
    Babs
    wrote on 5 Jul 2019, 12:14 last edited by
    #1

    Hello,
    Is it possible to connect more than on slot to a signal. For example in my program i do those two connect:

        connect(systecDev,&QCanBusDevice::framesReceived,this,&PowerSupplyControl::fillDeviceDatas);
    //////
        connect(systecDev, &QCanBusDevice::framesReceived, this, &DevicesManagement::processReceivedFrames);
    
    
    

    But only one of my slot is executed.
    Anyone can Help pls?

    A J 2 Replies Last reply 5 Jul 2019, 12:23
    0
    • B Babs
      5 Jul 2019, 12:14

      Hello,
      Is it possible to connect more than on slot to a signal. For example in my program i do those two connect:

          connect(systecDev,&QCanBusDevice::framesReceived,this,&PowerSupplyControl::fillDeviceDatas);
      //////
          connect(systecDev, &QCanBusDevice::framesReceived, this, &DevicesManagement::processReceivedFrames);
      
      
      

      But only one of my slot is executed.
      Anyone can Help pls?

      A Offline
      A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on 5 Jul 2019, 12:23 last edited by
      #2

      @Babs It is of course possible to connect multiple slots to one signal - that's one of the essences of Signals&Slots.

      If you, however, react to this signal with a method like readFrames(), then the second slot will have nothing to read, as the buffer is already empty.

      So depending on your need you can either call other methods from your first slot, or emit a signal, or...

      Regards

      Qt has to stay free or it will die.

      B 1 Reply Last reply 5 Jul 2019, 12:31
      5
      • B Babs
        5 Jul 2019, 12:14

        Hello,
        Is it possible to connect more than on slot to a signal. For example in my program i do those two connect:

            connect(systecDev,&QCanBusDevice::framesReceived,this,&PowerSupplyControl::fillDeviceDatas);
        //////
            connect(systecDev, &QCanBusDevice::framesReceived, this, &DevicesManagement::processReceivedFrames);
        
        
        

        But only one of my slot is executed.
        Anyone can Help pls?

        J Offline
        J Offline
        J.Hilk
        Moderators
        wrote on 5 Jul 2019, 12:25 last edited by J.Hilk 7 May 2019, 12:26
        #3

        @Babs

        So, is PowerSupplyControl a base class of DevicesManagement or vice versa ?

        do you really want to call the base class slot?


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        B 1 Reply Last reply 5 Jul 2019, 12:32
        0
        • A aha_1980
          5 Jul 2019, 12:23

          @Babs It is of course possible to connect multiple slots to one signal - that's one of the essences of Signals&Slots.

          If you, however, react to this signal with a method like readFrames(), then the second slot will have nothing to read, as the buffer is already empty.

          So depending on your need you can either call other methods from your first slot, or emit a signal, or...

          Regards

          B Offline
          B Offline
          Babs
          wrote on 5 Jul 2019, 12:31 last edited by
          #4

          @aha_1980 thank you .
          Indeed i read to this signal with readFrame(). For my function processReceivedFrame() i store the received frames on a vector like this:

          void DevicesManagement::processReceivedFrames()
          {
          
              while(systecDev->framesAvailable()){
                  QCanBusFrame frame=systecDev->readFrame();
                  qDebug()<<frame.toString();
                  QString str=frame.payload().toHex().toUpper();
                  receivedMessages.push_back(str);
                  emit messagesListModified();
          
              }
          }
          

          And in my second method fillDeviceDatas, i browse my vector in order to store all the parameters receive in their respective variable.

          void PowerSupplyControl::fillDeviceDatas()
          {
              for(auto &payload:receivedMessages){
                  quint16 entry=(payload.left(6).right(2) + payload.left(4).right(2)).toUShort(nullptr,16);
                  quint8 subEntry=static_cast<quint8>(payload.left(8).right(2).toUShort(nullptr,16));
                  if(payload.startsWith("43")){
                      QString message=payload.right(8);
                      switch (entry) {
                      case SIMMER_INDEX:
                          updateSimmerObjects(subEntry,message);
                          break;
          
                      case CHARGE_INDEX:
                          updateChargeObjects(subEntry,message);
                          break;
          
                      case FAN_INDEX:
                          UpdateFANObjects(subEntry,message);
                          break;
          
                      case SYNC_INDEX:
                          updateSynchroDelay(message);
                          break;
          
                      case DEV_PROFILE_INDEX:
                          updateDeviceProfile(message);
                          break;
                      default:
                          break;
                      case PDOTX1_MAP_PARAMETER:
                          updatePDOMappRData(subEntry,message,1);
                          break;
          
                      case PDOTX2_MAP_PARAMETER:
                          updatePDOMappRData(subEntry,message,2);
                          break;
          
                      case PDOTX3_MAP_PARAMETER:
                          updatePDOMappRData(subEntry,message,3);
                          break;
          
                      case PDOTX4_MAP_PARAMETER:
                          updatePDOMappRData(subEntry,message,4);
                          break;
                      }
                  }
              }
          }
          

          In qml part i send read requests to my device and it response successfuly. May you have an idea of why my second slot fillDeviceDatas() is not executed.

          1 Reply Last reply
          0
          • J J.Hilk
            5 Jul 2019, 12:25

            @Babs

            So, is PowerSupplyControl a base class of DevicesManagement or vice versa ?

            do you really want to call the base class slot?

            B Offline
            B Offline
            Babs
            wrote on 5 Jul 2019, 12:32 last edited by Babs 7 May 2019, 12:32
            #5

            @J.Hilk No there is no Inheritance relationship between those two classes.

            J 1 Reply Last reply 5 Jul 2019, 12:33
            0
            • B Babs
              5 Jul 2019, 12:32

              @J.Hilk No there is no Inheritance relationship between those two classes.

              J Offline
              J Offline
              J.Hilk
              Moderators
              wrote on 5 Jul 2019, 12:33 last edited by
              #6

              @Babs and those 2 connects are in the same class ?


              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              B 1 Reply Last reply 5 Jul 2019, 12:33
              0
              • J J.Hilk
                5 Jul 2019, 12:33

                @Babs and those 2 connects are in the same class ?

                B Offline
                B Offline
                Babs
                wrote on 5 Jul 2019, 12:33 last edited by
                #7

                @J.Hilk no the first is in DeviceManagement and the second in PowerSupplyControl

                J 1 Reply Last reply 5 Jul 2019, 12:35
                0
                • B Babs
                  5 Jul 2019, 12:33

                  @J.Hilk no the first is in DeviceManagement and the second in PowerSupplyControl

                  J Offline
                  J Offline
                  J.Hilk
                  Moderators
                  wrote on 5 Jul 2019, 12:35 last edited by
                  #8

                  @Babs and you're sure, that systecDev is a valid- in fact the same - instance in both classes ?


                  Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                  Q: What's that?
                  A: It's blue light.
                  Q: What does it do?
                  A: It turns blue.

                  B 2 Replies Last reply 5 Jul 2019, 12:35
                  2
                  • J J.Hilk
                    5 Jul 2019, 12:35

                    @Babs and you're sure, that systecDev is a valid- in fact the same - instance in both classes ?

                    B Offline
                    B Offline
                    Babs
                    wrote on 5 Jul 2019, 12:35 last edited by
                    #9

                    @J.Hilk systecDev is a global

                    1 Reply Last reply
                    0
                    • J J.Hilk
                      5 Jul 2019, 12:35

                      @Babs and you're sure, that systecDev is a valid- in fact the same - instance in both classes ?

                      B Offline
                      B Offline
                      Babs
                      wrote on 5 Jul 2019, 12:37 last edited by
                      #10

                      @J.Hilk I found out what my problem was. My two slot are excuted. The problem was that it didn't pass a certain condition in the second slot. My problem is solved. Thank you for your responses.
                      Best Regards,

                      1 Reply Last reply
                      2

                      4/10

                      5 Jul 2019, 12:31

                      • Login

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