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. [SOLVED]QTimer problem
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]QTimer problem

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.2k Views 1 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.
  • T Offline
    T Offline
    toho71
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      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.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • T Offline
        T Offline
        toho71
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • T Offline
          T Offline
          toho71
          wrote on last edited by
          #4

          Oh I found som redundant code too here ClearVectors;

          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