Qt QLCDNumber QTimer Digital Clock
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!
Code:
StatusBar::StatusBar()
{
createButtons();
time = new QTime(11,
0,
0);
};
void StatusBar::createButtons()
{
...
lcdSimulation->setNumDigits(8);
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);
};
Re: Qt QLCDNumber QTimer Digital Clock
Line 23 should be :
Code:
time = time->addMSecs(1000);
Carefully read the description of the method QTime::addMSecs