
Originally Posted by
Niamita
i set timer at two places one to update paint and one to update time
Ok you can use two timers like this
...
protected:
private:
int timeUpdateTimer;
int paintUpdateTimer;
}
void MyClass
::MyClass(QObject * parent
) {
timeUpdateTimer = 0; // Just to be safe.
paintUpdateTimer = 0;
...
timeUpdateTimer = startTimer(1000); // Update time every 1 second
paintUpdateTimer= startTimer(500); // Update paint every 0.5 second, you can move this to any place in you class
}
{
if(timeUpdateTimer == event->timerID())
{
QString timeString
= time.
toString("hh:mm");
label->setText(timeString);
}
else if(paintUpdateTimer == event->timerID())
{
widget->update(); //update paint here
}
else
{
killTimer(event->timerId()); //Have this, till you clearly understand how QObject, abd QTimers work
}
}
class MyClass : QObject {
...
protected:
void timerEvent(QTimerEvent * event);
private:
int timeUpdateTimer;
int paintUpdateTimer;
}
void MyClass::MyClass(QObject * parent)
{
timeUpdateTimer = 0; // Just to be safe.
paintUpdateTimer = 0;
...
timeUpdateTimer = startTimer(1000); // Update time every 1 second
paintUpdateTimer= startTimer(500); // Update paint every 0.5 second, you can move this to any place in you class
}
void MyClass::timerEvent(QTimerEvent * event)
{
if(timeUpdateTimer == event->timerID())
{
QTime time = QTime::currentTime();
QString timeString = time.toString("hh:mm");
label->setText(timeString);
}
else if(paintUpdateTimer == event->timerID())
{
widget->update(); //update paint here
}
else
{
killTimer(event->timerId()); //Have this, till you clearly understand how QObject, abd QTimers work
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks