qtimer array in console application



  • 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 !

  • Qt Champions 2018

    @SherifOmran

    QTimer timers[1] ;

    that is an array with ONE element, not TWO.

    Regards



  • 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.