One quick way
class TimeLabel
: public QLabel{
Q_OBJECT
public:
explicit TimeLabel
(QWidget * parent
= 0) {
startTimer(50); // Update time every 50 ms
}
protected:
{
setText
(QDateTime::currentDateTime().
toString());
}
};
int main(int argc, char ** argv)
{
TimeLabel label;
label.show();
return app.exec();
}
#include "main.moc"
class TimeLabel : public QLabel
{
Q_OBJECT
public:
explicit TimeLabel(QWidget * parent = 0)
: QLabel(parent)
{
startTimer(50); // Update time every 50 ms
}
protected:
void timerEvent(QTimerEvent *)
{
setText(QDateTime::currentDateTime().toString());
}
};
int main(int argc, char ** argv)
{
QApplication app(argc, argv);
TimeLabel label;
label.show();
return app.exec();
}
#include "main.moc"
To copy to clipboard, switch view to plain text mode
Bookmarks