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->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);
};
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);
};
To copy to clipboard, switch view to plain text mode
Bookmarks