How to Stack a list of emit to send
-
I am creating a simulator for my software, thus i have a sequence of signals to send.
I created a timer so that each signals is called.
Thought of using Qlist to do it.void emitSlot() {
emit travelStatusChanged(1,2,3,16); emit travelStatusChanged(4,2,3,16); emit travelStatusChanged(1,3,4,16); emit travelStatusChanged(4,3,4,16); emit travelStatusChanged(1,4,5,16); } ```timer1 = new QTimer(this); connect(timer1, SIGNAL(timeout), this, SLOT(nextEmit())); timer1->start(1200);
-
Hi,
You could encapsulate your parameters in a class/struct and then put that in a QList/QVector. From there it will be easier to generate the sequence.
-
This post is deleted! -
I am loss, is there a library for stacking signals together?
QVector list; list<<"emit travelStatusChanged(4,1,2,16)" <<"emit travelStatusChanged(1,2,3,16)" <<"emit travelStatusChanged(4,2,3,16)"<< "emit travelStatusChanged(1,3,4,16)" <<"emit travelStatusChanged(4,3,4,16)"<< "emit travelStatusChanged(1,4,5,16)" <<"emit travelStatusChanged(4,4,5,16)"<< "emit travelStatusChanged(1,5,6,16)" <<"emit travelStatusChanged(4,5,6,16)"<< "emit travelStatusChanged(1,6,7,16)" <<"emit travelStatusChanged(4,6,7,16)"<< "emit travelStatusChanged(1,7,8,16)" <<"emit travelStatusChanged(4,7,8,16)"<< "emit travelStatusChanged(1,8,9,16)" <<"emit travelStatusChanged(4,8,9,16)"<< "emit travelStatusChanged(1,9,10,16)" <<"emit travelStatusChanged(4,9,10,16)"<< "emit travelStatusChanged(1,10,11,16)" <<"emit travelStatusChanged(4,10,11,16)"; timerForLEDForwardBackward = new QTimer(this); connect(timerForLEDForwardBackward,SIGNAL(timeout()),this,SLOT(nextSignalSlot())); timerForLEDForwardBackward->start(12000); void MainWindow::nextSignalSlot() { list.at(list.at()+1); }
-
I meant: create a list of parameter objects.
struct TravelStatus : { int w; // replace by meaningful names int x; int y; int z; } // in your class add a member variable. QList<TravelStatus> _travelStatusList; void MyClass::sendNextStatus() { TravelStatus travelStatus = _travelStatusList.takeFirst(); emit travelStatusChanged(travelStatus.w, travelStatus.x, travelStatus.y, travelStatus.z); }
For more clean design, use TravelStatus in you signals and slots, so if you need to change it at some point, then you don't have to change all your signals and slots signatures.