Results 1 to 2 of 2

Thread: problem with QTimer

  1. #1
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default problem with QTimer

    i have written a piece of code in which i update my view after every millisecond ,i do this by clicking a button,but when i reclick the button the view is updated twice the speed of its previous update and this speed seems to increase by every click..here is some code to give you a idea..
    Qt Code:
    1. QTimer *timerProg;
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. ..
    2. timerProg = new QTimer();
    3. ..
    4.  
    5. void Progress::startProgress()
    6. {
    7. rec_button = TRUE;
    8. connect(timerProg,SIGNAL(timeout()),this,SLOT(advance()));
    9. timerProg->start(ROTATION_TIME);
    10. }
    11.  
    12. void Progress::advance()
    13. {
    14. if(rotation < 260)
    15. {
    16. rotation += ANGLE_INCREASE;
    17. rotation %= TOTAL_ROTATION;
    18. update();
    19. }
    20. else
    21. {
    22. timerProg->stop();
    23. rotation = -90;
    24. }
    25. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: problem with QTimer

    You connect to the timer each time you click the button, so after 10 clicks you'll timer will be connected 10 times, effectively multiplying the number of times the slot is called. It is enough to connect once when you create the timer and then only start the timer if it is not already running.

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

    salmanmanekia (13th August 2008)

Similar Threads

  1. Problem wit QTimer, different time, why?
    By perseo in forum Qt Programming
    Replies: 6
    Last Post: 8th August 2008, 09:41
  2. PyQt QTimer problem { FIXED }
    By WinchellChung in forum Newbie
    Replies: 0
    Last Post: 1st March 2008, 16:50
  3. QTimer and QSqlDatabase Problem
    By smtgra011 in forum Qt Programming
    Replies: 6
    Last Post: 4th July 2007, 16:37
  4. QTimer problem
    By vv in forum Qt Programming
    Replies: 9
    Last Post: 3rd July 2007, 08:13
  5. QTimer problem ... it runs but never triggs
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 4th July 2006, 12:54

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.