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. How to Stack a list of emit to send
Forum Updated to NodeBB v4.3 + New Features

How to Stack a list of emit to send

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 1.3k 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

    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);
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      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
      1
      • H Offline
        H Offline
        houmingc
        wrote on last edited by houmingc
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • H Offline
          H Offline
          houmingc
          wrote on last edited by houmingc
          #4

          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);    
          }
          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            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.

            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

            • Login

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