PDA

View Full Version : Qt QLCDNumber QTimer Digital Clock



wallacesoh
22nd October 2013, 05:02
I am trying to create a digital clock. However, my purpose is not getting the currentTime(). Instead, I am defining my own time and incrementing the time from there onwards.

However, in my codes, I am able to call tickSimulation(), but the clock timer won't start ticking. It just stuck at 11:00:00. Is adding addMSecs(1000) the correct way to increment the time?

Please help. Thanks!


StatusBar::StatusBar()
{
createButtons();
time = new QTime(11, 0, 0);
};

void StatusBar::createButtons()
{
...
lcdSimulation = new QLCDNumber;
lcdSimulation->setNumDigits(8);
simulationTimer = new QTimer;
simulationTimer->start(1000);
QObject::connect(simulationTimer, SIGNAL(timeout()), this, SLOT(tickSimulation()));
addWidget(lcdSimulation);
...
}

void StatusBar::tickSimulation()
{
QString text = time->toString(Qt::TextDate);
lcdSimulation->display(text);
time->addMSecs(1000);
};

Lesiok
22nd October 2013, 07:40
Line 23 should be :
time = time->addMSecs(1000);
Carefully read the description of the method QTime::addMSecs