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. qtimer array in console application

qtimer array in console application

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 703 Views
  • 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.
  • S Offline
    S Offline
    SherifOmran
    wrote on last edited by aha_1980
    #1

    i am trying to create two qtimers and each one should fire at different time
    in a console application```

       QApplication a(argc, argv);
      int counter=0; 
      QTimer timers[1] ;
        for (int k=0; k<2; k++)
        {
            timers[counter].singleShot(5000+counter*1000, [&](){
                TimerUpdate("");
            });
            counter=counter+1;
        }
    

    void TimerUpdate(Qstring job)
    {
    //do thing
    }

    
    this code has an error in the QTimer initialization when it is more than 1. As long as k<1 in the loop it works fine.
    The error is assert fail, index out of range !
    aha_1980A 1 Reply Last reply
    0
    • S SherifOmran

      i am trying to create two qtimers and each one should fire at different time
      in a console application```

         QApplication a(argc, argv);
        int counter=0; 
        QTimer timers[1] ;
          for (int k=0; k<2; k++)
          {
              timers[counter].singleShot(5000+counter*1000, [&](){
                  TimerUpdate("");
              });
              counter=counter+1;
          }
      

      void TimerUpdate(Qstring job)
      {
      //do thing
      }

      
      this code has an error in the QTimer initialization when it is more than 1. As long as k<1 in the loop it works fine.
      The error is assert fail, index out of range !
      aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @SherifOmran

      QTimer timers[1] ;

      that is an array with ONE element, not TWO.

      Regards

      Qt has to stay free or it will die.

      1 Reply Last reply
      4
      • S Offline
        S Offline
        SherifOmran
        wrote on last edited by
        #3

        Thank you for the check. When i inspected my code again, i found that it was made 2, but the mistake was somewhere else in an internal loop trying to call an item in a qlist that is not found.

        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