יום שישי, 24 במאי 2013

QTimer

The QTimer class part of the QTCore is used to implement timer functionality in QT.

The following steps used to create and operate the QTimer.
Constract the timer :
mTimer = new QTimer (this);
Note the the parent (this) assignment is used to assign the timer to its parent in order to allow automatic deletion of the timer in case were its parent delete.

Setting the timer interval in mili sec.
mTimer –> SetInterval (500); //2Hz
The timer resolution is depends on the system resolution .
Qt may unable to deliver the requested number of timer clicks.

Connecting the timer signal (Fire ) to the slot (event)

mTimerParent->connect(mTimer, SIGNAL(timeout()), this, SLOT(OnTimeOutFired()));
The class that implements the slot should inherit from QObject.

The callback function :
void TimerParent::OnTimeOutFired()
{
  //The callback
}

Starting the timer:

mTimer->start();

Stopping the timer

mTimer->stop();

Set as single shot :
mTimer->setSingleShot(true)

Use static call in order to run asingle shot timer

 QTimer.singleShot(1000, &OnTimeOutFiredOnceCls, SLOT(OnTimeOutFiredOnce()));
 

אין תגובות:

הוסף רשומת תגובה