Connect multiple slots to one signal
-
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? -
@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
-
@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.