#include <QtGui>
Q_OBJECT
public:
setCentralWidget(timeLabel);
time.start();
updateDisplay();
connect(&timer, SIGNAL(timeout()), this, SLOT(updateDisplay()));
timer.start(500); // twice per second
}
public slots:
void updateDisplay() {
int secs = time.elapsed() / 1000;
int mins = (secs / 60) % 60;
int hours = (secs / 3600);
secs = secs % 60;
timeLabel
->setText
(QString("%1:%2:%3") }
private:
};
int main(int argc, char *argv[])
{
mainwindow m;
m.show();
return app.exec();
}
#include "main.moc"
#include <QtGui>
class mainwindow: public QMainWindow {
Q_OBJECT
public:
mainwindow(QWidget *p = 0): QMainWindow(p) {
timeLabel = new QLabel(this);
setCentralWidget(timeLabel);
time.start();
updateDisplay();
connect(&timer, SIGNAL(timeout()), this, SLOT(updateDisplay()));
timer.start(500); // twice per second
}
public slots:
void updateDisplay() {
int secs = time.elapsed() / 1000;
int mins = (secs / 60) % 60;
int hours = (secs / 3600);
secs = secs % 60;
timeLabel->setText(QString("%1:%2:%3")
.arg(hours, 2, 10, QLatin1Char('0'))
.arg(mins, 2, 10, QLatin1Char('0'))
.arg(secs, 2, 10, QLatin1Char('0')) );
}
private:
QLabel *timeLabel;
QTime time;
QTimer timer;
};
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
mainwindow m;
m.show();
return app.exec();
}
#include "main.moc"
To copy to clipboard, switch view to plain text mode
Bookmarks