QTimer
General and Desktop
3
Posts
2
Posters
3.0k
Views
1
Watching
-
Hello.
Timer constructor: QTimer::QTimer (QObject * parent = 0);
Use parent parameter and your class will automatically delete timer.
@
//constructor--
Class1::Class1()
{
pTimer = new QTimer(this);
........
.........
pTimer->start(1000);
}
@It works If your class inherits from QObject. If not, then delete it in destructor.
Also you can use member timer rather than pointer.
@
// header
class Class1 {
public:
Class1();
~Class1();
private:
QTimer timer_;
};// cpp
Class1::Class1() : timer_()
{
...
...
timer_.start(1000);
};
@