How to stop a QTimer::singleShot
-
wrote on 31 Mar 2011, 14:10 last edited by
Hi all,
in my application I sometimes start a QTimer::singleShot but in some situation I need to stop it before it trigger.Is it possibile to stop it?
-
wrote on 31 Mar 2011, 14:16 last edited by
"QTimer::stop() ":http://doc.qt.nokia.com/4.7/qtimer.html#stop does not work?
-
wrote on 31 Mar 2011, 14:17 last edited by
[quote author="Volker" date="1301580963"]"QTimer::stop() ":http://doc.qt.nokia.com/4.7/qtimer.html#stop does not work?[/quote]
I start it with:
@
QTimer::singleShot(360000, this, SLOT(mySlot()));
@ -
wrote on 31 Mar 2011, 14:18 last edited by
As long as you keep a reference to the timer, you can stop it. If you used the static function to trigger the single shot, you're out of luck (well, I guess you could come up with a hack, but please don't).
-
wrote on 31 Mar 2011, 14:24 last edited by
Sorry, I misread singleShot with setSingleShot :-(
In this case you'll have to stick to the solutions Andre mentioned.
-
wrote on 31 Mar 2011, 14:29 last edited by
[quote author="Luca" date="1301581026"]
[quote author="Volker" date="1301580963"]"QTimer::stop() ":http://doc.qt.nokia.com/4.7/qtimer.html#stop does not work?[/quote]I start it with:
@
QTimer::singleShot(360000, this, SLOT(mySlot()));
@
[/quote]If you change that to something like:
@
m_myLongTimer = new QTimer(this);
m_myLongTimer->setInterval(360000);
m_myLongTimer->setSingleShot(true);
connect(m_myLongTimer, SIGNAL(timeout()), SLOT(myslot()));
m_myLongTimer->start();
@You can use this to stop again:
@
m_myLongTimer->stop();
@Edit: added connect call to sample code
-
wrote on 31 Mar 2011, 14:30 last edited by
So it should be better to use a QTimer, set it with:
@
setSingleShot();
@thanks.
1/7