Results 1 to 5 of 5

Thread: Total time in QTimer

  1. #1
    Join Date
    May 2009
    Posts
    14
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Total time in QTimer

    Hi all,

    i am using QTimer, what i want to do is to have a total time, for example 10 minutes and in these 10 minutes, do something every 5 seconds. I know how to put the interval os 5 seconds, but i don´t know how to control that QTimer lasts 10 minutes, and after 10 minutes its stop.

    And also how can i store in which interval i am, because what i want to store is the value of a variable in each interval, so i need the interval, and i don´t know how to get it

    Thank very much.
    Last edited by martisho; 11th November 2009 at 15:11.

  2. #2
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Total time in QTimer

    Quote Originally Posted by martisho View Post
    Hi all,

    i am using QTimer, what i want to do is to have a total time, for example 10 minutes and in these 10 minutes, do something every 5 seconds. I know how to put the interval os 5 seconds, but i don´t know how to control that QTimer lasts 10 minutes, and after 10 minutes its stop.

    And also how can i store in which interval i am, because what i want to store is the value of a variable in each interval, so i need the interval, and i don´t know how to get it

    Thank very much.
    You can use 2 QTimer instances. One will be responsible for invoking in each 5 seconds and another will stop first after 10 mins.
    Use singleShot for second timer.

  3. The following user says thank you to yogeshgokul for this useful post:

    martisho (13th November 2009)

  4. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Total time in QTimer

    Use a QTimeLine:
    Qt Code:
    1. // Construct a 1-second timeline with a frame range of 0 - 100
    2. QTimeLine *timeLine = new QTimeLine(1000, this);
    3. timeLine->setFrameRange(0, 100);
    4. connect(timeLine, SIGNAL(frameChanged(int)), progressBar, SLOT(setValue(int)));
    To copy to clipboard, switch view to plain text mode 

  5. The following user says thank you to Lykurg for this useful post:

    martisho (13th November 2009)

  6. #4
    Join Date
    May 2009
    Posts
    14
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Total time in QTimer

    Ok, thanks!

    And how can i store in wich interval i am, because what i want to store is the value of a variable in each interval, so i need the interval, and i don´t know how to get it.

  7. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Total time in QTimer

    Quote Originally Posted by martisho View Post
    And how can i store in wich interval i am
    ??? the frameChanged parameter is your interval! Read the docs about that.

  8. The following user says thank you to Lykurg for this useful post:

    martisho (16th November 2009)

Similar Threads

  1. QTimer stops after system time change
    By djurodrljaca in forum Qt Programming
    Replies: 3
    Last Post: 1st May 2009, 21:36
  2. Problem wit QTimer, different time, why?
    By perseo in forum Qt Programming
    Replies: 6
    Last Post: 8th August 2008, 10:41
  3. How to constantly refresh time on a view
    By salmanmanekia in forum Qt Programming
    Replies: 5
    Last Post: 23rd June 2008, 13:44
  4. QDateTime GMT add sec. or - sec. from locale time....
    By patrik08 in forum Qt Programming
    Replies: 2
    Last Post: 20th February 2007, 17:39
  5. Replies: 6
    Last Post: 17th March 2006, 18:48

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.