Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Better implementation than function hopping (solved)
Forum Updated to NodeBB v4.3 + New Features

Better implementation than function hopping (solved)

Scheduled Pinned Locked Moved General and Desktop
5 Posts 5 Posters 1.2k Views 2 Watching
  • 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.
  • H Offline
    H Offline
    houmingc
    wrote on last edited by houmingc
    #1

    Although the code below works. I have 60 function needs to run consecutively.
    Anyone can provide a better solution, please

    void 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);
    
    }
    
    1 Reply Last reply
    0
    • H Offline
      H Offline
      Huulivoide
      wrote on last edited by
      #2

      Wouldn't a for loop do it?
      Or a non-singleshoot timer, that fires every x seconds?

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        Isn't that just a variation of the question asked in this thread ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • J Offline
          J Offline
          Jeroen3
          wrote on last edited by Jeroen3
          #4

          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

          1 Reply Last reply
          0
          • Y Offline
            Y Offline
            yoavmil
            wrote on last edited by
            #5

            QStateMachine Class may be the answer, also take a look at postDelayedEvent(QEvent * event, int delay)

            1 Reply Last reply
            0

            • Login

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