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. Timer question
Forum Updated to NodeBB v4.3 + New Features

Timer question

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 1.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.
  • M Offline
    M Offline
    MoonChild
    wrote on last edited by
    #1

    How do I do to restart a QTimer of 1 minute in one function called PushButtonHandler each time I push a button, how do I stop the running timer, I cant use Timer->stop() before the declaration of the QTimer!!!!!!!, already tried if (isActive(&Timer)==TRUE ), does't work,Help please.
    @
    void MainWindow::PushButtonHandler()
    {
    do
    {
    if (seconds==0)
    seconds=10;

        //if (isActive(&Timer)==TRUE )?????????????????
        //    Timer->stop();?????????????????????
    
      // if (QTimer::isActive ())=TRUE)??????????????????
    
       //     QTimer::~QTimer ()); ????????????????
    
       t=t+5;
       seconds=seconds+5;
    }
    while (seconds>45);
    
    if (seconds==45)
      seconds=15;
    
    ui->lcdNumber_2->display(seconds);
    
    
    if (t>=6)
         {
             t--;
             QTimer *Timer = new QTimer(this);
             Timer->setInterval(36000);
             Timer->setSingleShot(true);
             connect(Timer, SIGNAL(timeout()), SLOT(Timer()));
             Timer->start();
          }
    

    }
    @

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mlong
      wrote on last edited by
      #2

      [Moderator's note: I split this into its own thread. Please start new threads for new questions, even if they're "sort of" related to an old thread.]

      But to answer your question, make the QTimer * a member of your class rather than a locally-created timer in the handler. (So you only create one timer.)

      Then you can just call theTimer->start() to start/restart it, or theTimer->stop() to stop it.

      Also, as a side note, never call a destructor explicitly! You'd want to use delete to delete a timer, if that's what you wanted to do.

      Software Engineer
      My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #3

        Also: get rid of the loop in there. You do not need it.

        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