You don't need the thread. The timer will let you know when a specified amount of time has passed. Here is a sample code:
#include <QApplication>
#include <QLabel>
#include <QTimer>
#include <QDateTime>
Q_OBJECT
public:
public slots:
void doIt
(){ m_label
->setText
(QDateTime::currentDateTime().
toString());
} private:
};
#include "main.moc"
int main(int argc, char **argv){
Dummy dummy(&label);
dummy.doIt();
QObject::connect(&t,
SIGNAL(timeout
()),
&dummy,
SLOT(doIt
()));
t.start(1000);
label.show();
return app.exec();
}
#include <QApplication>
#include <QLabel>
#include <QTimer>
#include <QDateTime>
class Dummy : public QObject {
Q_OBJECT
public:
Dummy(QLabel *l) : QObject(){m_label = l; }
public slots:
void doIt(){ m_label->setText(QDateTime::currentDateTime().toString()); }
private:
QLabel *m_label;
};
#include "main.moc"
int main(int argc, char **argv){
QApplication app(argc, argv);
QLabel label;
QTimer t;
Dummy dummy(&label);
dummy.doIt();
QObject::connect(&t, SIGNAL(timeout()), &dummy, SLOT(doIt()));
t.start(1000);
label.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks