Qtimer Signal Slot
Hi I'd like to do something like this: QTimer::singleShot(5000, this, SLOT(MySlot(iID))); to get the ID (can be 1 to 16) and know which ID did kick off the singleShot. However, that seems not to be possible with on-board tools. Any idea how this can be e. The QTimer class provides a high-level programming interface for timers. To use it, create a QTimer, connect its timeout signal to the appropriate slots, and call start. From then on, it will emit the timeout signal at constant intervals. Example for a one second (1000 millisecond) timer (from the Analog Clock example).
Home All Classes Main Classes Annotated Grouped Classes Functions |
The QTimer class provides timer signals and single-shot timers.More...
#include <qtimer.h>
Inherits QObject.
Public Members
- QTimer ( QObject * parent = 0, const char * name = 0 )
- ~QTimer ()
- bool isActive () const
- int start ( int msec, bool sshot = FALSE )
- void changeInterval ( int msec )
- void stop ()
- int timerId () const
Signals
- void timeout ()
Static Public Members
- void singleShot ( int msec, QObject * receiver, const char * member )
Detailed Description
The QTimer class provides timer signals and single-shot timers.It uses timer events internally toprovide a more versatile timer. QTimer is very easy to use:create a QTimer, call start() to start it and connect itstimeout() to the appropriate slots. When the time is up it willemit the timeout() signal.
Note that a QTimer object is destroyed automatically when itsparent object is destroyed.
Example:
You can also use the static singleShot() function to create asingle shot timer.
As a special case, a QTimer with timeout 0 times out as soon asall the events in the window system's event queue have beenprocessed.
This can be used to do heavy work while providing a snappyuser interface:
myObject->processOneThing() will be called repeatedly and shouldreturn quickly (typically after processing one data item) so thatQt can deliver events to widgets and stop the timer as soon as ithas done all its work. This is the traditional way ofimplementing heavy work in GUI applications; multi-threading isnow becoming available on more and more platforms, and we expectthat null events will eventually be replaced by threading.
Note that QTimer's accuracy depends on the underlying operatingsystem and hardware. Most platforms support an accuracy of 20ms;some provide more. If Qt is unable to deliver the requestednumber of timer clicks, it will silently discard some.
An alternative to using QTimer is to call QObject::startTimer()for your object and reimplement the QObject::timerEvent() eventhandler in your class (which must, of course, inherit QObject).The disadvantage is that timerEvent() does not support suchhigh-level features as single-shot timers or signals.
Some operating systems limit the number of timers that may beused; Qt tries to work around these limitations.
See also Event Classes and Time and Date.
Member Function Documentation
QTimer::QTimer ( QObject * parent = 0, const char * name = 0 )
Constructs a timer called name, with the parent parent.Note that the parent object's destructor will destroy this timerobject.
QTimer::~QTimer ()
Destroys the timer.void QTimer::changeInterval ( int msec )
Changes the timeout interval to msec milliseconds.Qtimer Signal Slot Car
If the timer signal is pending, it will be stopped and restarted;otherwise it will be started.
See also start() and isActive().
bool QTimer::isActive () const
Returns TRUE if the timer is running (pending); otherwise returnsFALSE.
Example: t11/cannon.cpp.
void QTimer::singleShot ( int msec, QObject * receiver, const char * member ) [static]
This static function calls a slot after a given time interval.It is very convenient to use this function because you do not needto bother with a timerEvent orto create a local QTimer object.
Example:
This sample program automatically terminates after 10 minutes (i.e.600000 milliseconds).
The receiver is the receiving object and the member is theslot. The time interval is msec.
int QTimer::start ( int msec, bool sshot = FALSE )
Starts the timer with a msec milliseconds timeout, and returnsthe ID of the timer, or zero when starting the timer failed.If sshot is TRUE, the timer will be activated only once;otherwise it will continue until it is stopped.
Any pending timer will be stopped.
See also singleShot(), stop(), changeInterval(), and isActive().
Examples: aclock/aclock.cpp, dirview/dirview.cpp, distributor/distributor.ui.h, forever/forever.cpp, hello/hello.cpp, t11/cannon.cpp, and t13/cannon.cpp.
void QTimer::stop ()
Stops the timer.See also start().
Examples: dirview/dirview.cpp, t11/cannon.cpp, t12/cannon.cpp, and t13/cannon.cpp.
void QTimer::timeout () [signal]
This signal is emitted when the timer is activated.
Examples: aclock/aclock.cpp, dirview/dirview.cpp, distributor/distributor.ui.h, forever/forever.cpp, hello/hello.cpp, and t11/cannon.cpp.
int QTimer::timerId () const
Returns the ID of the timer if the timer is running; otherwise returns-1.
This file is part of the Qt toolkit.Copyright © 1995-2005Trolltech. All Rights Reserved.
Synopsis¶
Functions¶
- def interval ()
- def isActive ()
- def isSingleShot ()
- def setInterval (msec)
- def setSingleShot (singleShot)
- def timerId ()
Signals¶
- def timeout ()
Static functions¶
- def singleShot (arg__1, arg__2)
- def singleShot (msec, receiver, member)
Detailed Description¶
The PySide.QtCore.QTimer class provides repetitive and single-shot timers.
The PySide.QtCore.QTimer class provides a high-level programming interface for timers. To use it, create a PySide.QtCore.QTimer , connect its PySide.QtCore.QTimer.timeout() signal to the appropriate slots, and call PySide.QtCore.QTimer.start() . From then on it will emit the PySide.QtCore.QTimer.timeout() signal at constant intervals.
Example for a one second (1000 millisecond) timer (from the Analog Clock example):
From then on, the update() slot is called every second.
You can set a timer to time out only once by calling setSingleShot(true). You can also use the static QTimer.singleShot() function to call a slot after a specified interval:
In multithreaded applications, you can use PySide.QtCore.QTimer in any thread that has an event loop. To start an event loop from a non-GUI thread, use QThread.exec() . Qt uses the timer’s threadaffinity to determine which thread will emit the PySide.QtCore.QTimer.timeout() signal. Because of this, you must start and stop the timer in its thread; it is not possible to start a timer from another thread.
As a special case, a PySide.QtCore.QTimer with a timeout of 0 will time out as soon as all the events in the window system’s event queue have been processed. This can be used to do heavy work while providing a snappy user interface:
processOneThing() will from then on be called repeatedly. It should be written in such a way that it always returns quickly (typically after processing one data item) so that Qt can deliver events to widgets and stop the timer as soon as it has done all its work. This is the traditional way of implementing heavy work in GUI applications; multithreading is now becoming available on more and more platforms, and we expect that zero-millisecond QTimers will gradually be replaced by PySide.QtCore.QThread s.
Accuracy and Timer Resolution¶
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.
The accuracy of timers depends on the underlying operating system and hardware. Most platforms support a resolution of 1 millisecond, though the accuracy of the timer will not equal this resolution in many real-world situations.
If Qt is unable to deliver the requested number of timer clicks, it will silently discard some.
Alternatives to QTimer¶
An alternative to using PySide.QtCore.QTimer is to call QObject.startTimer() for your object and reimplement the QObject.timerEvent() event handler in your class (which must inherit PySide.QtCore.QObject ). The disadvantage is that PySide.QtCore.QTimer.timerEvent() does not support such high-level features as single-shot timers or signals.
Another alternative to using PySide.QtCore.QTimer is to use PySide.QtCore.QBasicTimer . It is typically less cumbersome than using QObject.startTimer() directly. See Timers for an overview of all three approaches.
Some operating systems limit the number of timers that may be used; Qt tries to work around these limitations.
See also
PySide.QtCore.QBasicTimerPySide.QtCore.QTimerEventQObject.timerEvent()TimersAnalog Clock ExampleWiggly Example
Parameters: | parent – PySide.QtCore.QObject |
---|
Constructs a timer with the given parent .
Return type: | PySide.QtCore.int |
---|
This property holds the timeout interval in milliseconds.
The default value for this property is 0. A PySide.QtCore.QTimer with a timeout interval of 0 will time out as soon as all the events in the window system’s event queue have been processed.
Setting the interval of an active timer changes its PySide.QtCore.QTimer.timerId() .
Return type: | PySide.QtCore.bool |
---|
This boolean property is true if the timer is running; otherwise false.
Qtimer Signal Slot Games
Return type: | PySide.QtCore.bool |
---|
This property holds whether the timer is a single-shot timer.
A single-shot timer fires only once, non-single-shot timers fire every PySide.QtCore.QTimer.interval() milliseconds.
See also
Parameters: | msec – PySide.QtCore.int |
---|
This property holds the timeout interval in milliseconds.
The default value for this property is 0. A PySide.QtCore.QTimer with a timeout interval of 0 will time out as soon as all the events in the window system’s event queue have been processed.
Setting the interval of an active timer changes its PySide.QtCore.QTimer.timerId() .
Parameters: | singleShot – PySide.QtCore.bool |
---|
This property holds whether the timer is a single-shot timer.
A single-shot timer fires only once, non-single-shot timers fire every PySide.QtCore.QTimer.interval() milliseconds.
See also
Parameters: |
|
---|
Qtimer Signal Slot Machine
This static function calls a slot after a given time interval.
It is very convenient to use this function because you do not need to bother with a PySide.QtCore.QObject.timerEvent() or create a local PySide.QtCore.QTimer object.
Example:
This sample program automatically terminates after 10 minutes (600,000 milliseconds).
The receiver is the receiving object and the member is the slot. The time interval is msec milliseconds.
See also
Parameters: |
|
---|
This function overloads PySide.QtCore.QTimer.start() .
Starts or restarts the timer with the timeout specified in PySide.QtCore.QTimer.interval() .
If PySide.QtCore.QTimer.singleShot() is true, the timer will be activated only once.
Parameters: | msec – PySide.QtCore.int |
---|
Starts or restarts the timer with a timeout interval of msec milliseconds.
Stops the timer.
- PySide.QtCore.QTimer.timeout()¶
Return type: | PySide.QtCore.int |
---|
Returns the ID of the timer if the timer is running; otherwise returns -1.