Results 1 to 9 of 9

Thread: how to use Multiple timers?

  1. #1
    Join Date
    Feb 2010
    Posts
    61
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default how to use Multiple timers?

    HI,

    i want to use multiple timers.
    for example to do some task shuld be done by using first timer interval and another task should be done for the second timer interval,
    actually for single timer i was using starttimer(time interval)
    so my Question is how to start second timer , i mean how to initiate the timer and distinguish from the first timer

    Could any one give me some sample code or any examples which are using multiple timers.

    Thnks in advance,,,
    QtlinuxNewbie

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how to use Multiple timers?

    See QTimer.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Feb 2010
    Posts
    61
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to use Multiple timers?

    i was using timer event. and doing a task for some time interval
    now i want to do another task with different time interval...
    ..
    hope u understood...

    Thnx

  4. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,499
    Thanked 277 Times in 272 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to use Multiple timers?

    Create as many instances of QTimer as You need. And run every one with different timeout.

  5. #5
    Join Date
    Feb 2010
    Posts
    61
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to use Multiple timers?

    ok thank you and shuld i run single timer event with different timer instances or multiple timer events???

  6. #6
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,499
    Thanked 277 Times in 272 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to use Multiple timers?

    I miss what is a problem.
    Simply You creates many QTimers and connect every of them to another slot.
    Just read QTimer class reference

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how to use Multiple timers?

    You can have multiple timer events with different intervals. See QTimerEvent and QObject::startTimer() (especially the return value of the latter)
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Sep 2012
    Posts
    32
    Thanks
    18
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: how to use Multiple timers?

    Quote Originally Posted by Lesiok View Post
    I miss what is a problem.
    Simply You creates many QTimers and connect every of them to another slot.
    Just read QTimer class reference
    Hi Lesiok,

    I had done what you explained. But it was delaying the process.
    means 6 Qtimers created and connected to 6 diff slots with different timeouts.

    but i am the timers are getting delayed. As per my application i need to run all the timers at a time.

    sample code of mine is --

    1st timer -
    timer_HMIScrLvl4 = new QTimer(this);
    connect(timer_HMIScrLvl4, SIGNAL(timeout()), this, SLOT(update_HMIScrLvl4()));
    timer_HMIScrLvl4->setInterval(100);
    2nd timer -
    Timer_failure_display = new QTimer(this);
    connect(Timer_failure_display, SIGNAL(timeout()), this, SLOT(failure_display()));
    Timer_failure_display->setInterval(250);
    3rd timer -
    Timer_footer = new QTimer(this);
    connect(Timer_footer, SIGNAL(timeout()), this, SLOT(footer()));
    Timer_footer->setInterval(250);
    4th timer -
    Timer_diagonostic_refresh = new QTimer(this);
    connect(Timer_diagonostic_refresh, SIGNAL(timeout()), this, SLOT(diagonostic_refresh()));
    Timer_diagonostic_refresh->setInterval(50);
    5th Timer -
    Timer_information_refresh = new QTimer(this);
    connect(Timer_information_refresh, SIGNAL(timeout()), this, SLOT(information_refresh()));
    Timer_information_refresh->setInterval(25);
    6th timer -
    Timer_footer = new QTimer(this);
    connect(Timer_footer, SIGNAL(timeout()), this, SLOT(footer()));
    Timer_footer->setInterval(250);
    1st & 2nd timers are the main timers i should not wanted them to be delayed, they should run at a time.

    Thanks in Advance.

    Forgive me if any thing i posted is against to the rules if the forum.

    plzz help me if possible as early as possible.

  9. #9
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,499
    Thanked 277 Times in 272 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to use Multiple timers?

    Quote Originally Posted by mahi6a1985 View Post
    Hi Lesiok,

    I had done what you explained. But it was delaying the process.
    means 6 Qtimers created and connected to 6 diff slots with different timeouts.

    but i am the timers are getting delayed. As per my application i need to run all the timers at a time.

    sample code of mine is --



    1st & 2nd timers are the main timers i should not wanted them to be delayed, they should run at a time.

    Thanks in Advance.

    Forgive me if any thing i posted is against to the rules if the forum.

    plzz help me if possible as early as possible.
    Are you sure you read the documentation? I think not. Quote from the QTimer documentation :
    Timers will never time out earlier than the specified timeout value and they are not guaranteed to time out at the exact value specified. In many situations, they may time out late by a period of time that depends on the accuracy of the system timers.
    .....
    If Qt is unable to deliver the requested number of timer clicks, it will silently discard some.

Similar Threads

  1. Multiple timers in single Application
    By Qt Coder in forum Qt Programming
    Replies: 47
    Last Post: 5th October 2012, 13:23
  2. Multiple UI files
    By Diblye in forum Newbie
    Replies: 5
    Last Post: 29th June 2012, 00:24
  3. Multiple completion
    By gruszczy in forum Qt Programming
    Replies: 1
    Last Post: 3rd March 2009, 22:40
  4. Replies: 0
    Last Post: 21st December 2006, 11:48
  5. How to cleanup timers properly?
    By jpn in forum Qt Programming
    Replies: 7
    Last Post: 6th July 2006, 17:52

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.