Better implementation than function hopping (solved)
-
Although the code below works. I have 60 function needs to run consecutively.
Anyone can provide a better solution, pleasevoid mainWindow() { QTimer *timerForLED = new QTimer(this); connect(timerForLED,SIGNAL(timeout()),this,SLOT(nextSignalSlot1())); timerForLED->start(12000); } void MainWindow::nextSignalSlot1() { TravelStatusChangedSlot(4,2,3,16); QTimer *timerForLED2 = new QTimer(this); connect(timerForLED2,SIGNAL(timeout()),this,SLOT(nextSignalSlot2())); timerForLED2->start(12000); } void MainWindow::nextSignalSlot2() { TravelStatusChangedSlot(4,1,2,16); QTimer *timerForLED3 = new QTimer(this); connect(timerForLED3,SIGNAL(timeout()),this,SLOT(nextSignalSlot3())); timerForLED3->start(12000); } void MainWindow::nextSignalSlot3() { TravelStatusChangedSlot(1,2,3,16); QTimer *timerForLED4 = new QTimer(this); connect(timerForLED4,SIGNAL(timeout()),this,SLOT(nextSignalSlot4())); timerForLED4->start(12000); }
-
Wouldn't a for loop do it?
Or a non-singleshoot timer, that fires every x seconds? -
Hi,
Isn't that just a variation of the question asked in this thread ?
-
In normal C we'd just put all the function pointers in an array and just iterate through the array.
Not sure if that is still easy to do in C++. Much like a state machine actually.However, you can easily run the same function 60 times on a different instance. Much more object oriented than timerForLEDX type of static stuff.
Take a lookt at http://doc.qt.io/qt-5/qlist.html -
QStateMachine Class may be the answer, also take a look at postDelayedEvent(QEvent * event, int delay)