Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Forum Updated on Feb 6th

    Solved Connect multiple slots to one signal

    QML and Qt Quick
    signal&slot qcanbusdevice
    3
    10
    3497
    Loading More Posts
    • 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
      Babs last edited by

      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?

      aha_1980 J.Hilk 2 Replies Last reply Reply Quote 0
      • aha_1980
        aha_1980 Lifetime Qt Champion @Babs last edited by

        @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 Reply Quote 5
        • J.Hilk
          J.Hilk Moderators @Babs last edited by J.Hilk

          @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

          Qt Needs YOUR vote: https://bugreports.qt.io/browse/QTQAINFRA-4121


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

          B 1 Reply Last reply Reply Quote 0
          • B
            Babs @aha_1980 last edited by

            @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 Reply Quote 0
            • B
              Babs @J.Hilk last edited by Babs

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

              J.Hilk 1 Reply Last reply Reply Quote 0
              • J.Hilk
                J.Hilk Moderators @Babs last edited by

                @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

                Qt Needs YOUR vote: https://bugreports.qt.io/browse/QTQAINFRA-4121


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

                B 1 Reply Last reply Reply Quote 0
                • B
                  Babs @J.Hilk last edited by

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

                  J.Hilk 1 Reply Last reply Reply Quote 0
                  • J.Hilk
                    J.Hilk Moderators @Babs last edited by

                    @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

                    Qt Needs YOUR vote: https://bugreports.qt.io/browse/QTQAINFRA-4121


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

                    B 2 Replies Last reply Reply Quote 2
                    • B
                      Babs @J.Hilk last edited by

                      @J.Hilk systecDev is a global

                      1 Reply Last reply Reply Quote 0
                      • B
                        Babs @J.Hilk last edited by

                        @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 Reply Quote 2
                        • First post
                          Last post