Results 1 to 4 of 4

Thread: How to stop a timer?

  1. #1
    Join Date
    Nov 2012
    Location
    Russia
    Posts
    221
    Thanks
    117
    Thanked 18 Times in 10 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default How to stop a timer?

    Hello!

    I created the MainWindow project and added:

    MainWindow.h
    Qt Code:
    1. private:
    2. void timerEvent( QTimerEvent *event );
    To copy to clipboard, switch view to plain text mode 

    I wrote in the constructor of the MainWindow:
    Qt Code:
    1. startTimer( 2000 );
    To copy to clipboard, switch view to plain text mode 

    I wrote:
    Qt Code:
    1. void MainWindow::timerEvent(QTimerEvent *event)
    2. {
    3. qDebug() << "timerEvent";
    4. }
    To copy to clipboard, switch view to plain text mode 

    How to stop this timer here:
    Qt Code:
    1. void MainWindow::on_startTransmissionButton_clicked()
    2. {
    3.  
    4. }
    To copy to clipboard, switch view to plain text mode 

    P.S. I cannot find timerEvent in the Qt's documentation
    The best game: www.gokgs.com

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,478
    Thanked 274 Times in 269 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to stop a timer?


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

    8Observer8 (28th August 2014)

  4. #3
    Join Date
    Nov 2012
    Location
    Russia
    Posts
    221
    Thanks
    117
    Thanked 18 Times in 10 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to stop a timer?

    Thank you very much!

    Qt Code:
    1. void MainWindow::on_startTransmissionButton_clicked()
    2. {
    3. m_timerID = startTimer( 2000 );
    4. }
    5.  
    6. void MainWindow::on_stopTransmissionButton_clicked()
    7. {
    8. killTimer( m_timerID );
    9. }
    To copy to clipboard, switch view to plain text mode 


    Added after 7 minutes:


    It is better:

    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::MainWindow)
    4. {
    5. // ...
    6.  
    7. ui->stopTransmissionButton->setEnabled( false );
    8. }
    9.  
    10. // ...
    11.  
    12. void MainWindow::on_startTransmissionButton_clicked()
    13. {
    14. m_timerID = startTimer( 2000 );
    15. ui->startTransmissionButton->setEnabled( false );
    16. ui->stopTransmissionButton->setEnabled( true );
    17. }
    18.  
    19. void MainWindow::on_stopTransmissionButton_clicked()
    20. {
    21. killTimer( m_timerID );
    22. ui->startTransmissionButton->setEnabled( true );
    23. ui->stopTransmissionButton->setEnabled( false );
    24. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by 8Observer8; 28th August 2014 at 07:16.
    The best game: www.gokgs.com

  5. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to stop a timer?

    Why muck with low level events and not simply use a QTimer?

    Cheers,
    _

Similar Threads

  1. Timer doesn't stop
    By smoon in forum Qt Programming
    Replies: 5
    Last Post: 11th June 2012, 16:08
  2. qt4.5, assert in timer event doesnt stop all timers
    By roybj in forum Qt Programming
    Replies: 1
    Last Post: 4th May 2011, 12:22
  3. timer problem(timer does not work)
    By masuk in forum Newbie
    Replies: 6
    Last Post: 14th February 2011, 05:00
  4. Program freeze when timer->stop();
    By gQt in forum Qt Programming
    Replies: 2
    Last Post: 8th January 2009, 14:05
  5. Timer delay
    By bmn in forum Qt Programming
    Replies: 11
    Last Post: 3rd June 2008, 11: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.