[SOLVED]QTimer problem



  • Hi
    I-m using a QTimer to show som stuff every second in my ui.
    I got a qtab and diffrent components on each side.
    When I select a new tab I want my qtimer to stop and the I start it again and I want it to make the call every second again.

    But when I switch between the tabs the timer interval seems to bee faster and faster????

    Her is some code.
    in the constructor
    @
    timer = new QTimer(this);
    timer->setInterval(1000);

    connect(this->timer,SIGNAL(timeout()),this,SLOT(timeOut()));
    

    @

    my timer start, stop and timeOut proc
    @
    /*

    • startTimer()

    • starts the timer to get the xmlfile
      */
      void Graphs::startTimer()
      {

      clearVectors();

      time = 0;
      this->timer->start();

    }

    /*

    • stoppTimer()
    • stopps the timer to get the xmlfile
      */
      void Graphs::stoppTimer()
      {
      this->timer->stop();
      }

    /*

    • TimeOut

    • the slot that Graphss and get the values to display in a interval
      */
      void Graphs::timeOut()
      {
      if(isChecked())
      {
      getXMLFile();
      qDebug() << time;
      time++;

      }
      }
      @

    Whats wrong???????????????

    Answer got another timer running in the background too and that also called the same slot;
    NO GOOD


  • Moderators

    I guess you are calling every time the constructor section somehow when switching tabs. However, this is not part of the code you posted.
    Set a break point in the constructor section when debugging. Then you can see, if my assumption is correct.



  • No I call the startTimer() like this in the tab selected slot

    @ int i = ui->graphsTab->currentIndex();

    this->stoppTimer();
    
    clearVectors();
    
    switch(i)
        {
            case 0: //Voltage G
            {
                setUpGenPlot();
    
                //if (isChecked())
                    startTimer();
                break;
            }
            case 1: //Voltage M
            {
                setUpNetPlot();
                //if (isChecked())
                    startTimer();
    
                break;
            }@
    

    etc.....



  • Oh I found som redundant code too here ClearVectors;


Log in to reply
 

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