View Full Version : [Qt] slot of QTimeEdit [problem resolved]
scorpiondezer
1st July 2008, 15:31
Hi everyone:)
I need to connect a QPushButton with QTimeEdit , for create a chronometer, I'm lost in the doc...:confused:
Thank you :)
What do you want QTimeEdit to do when the button is clicked?
scorpiondezer
1st July 2008, 16:05
The time run like a chrono
See documentation of QTimer. Here's an example:
QTimer *timer = new QTimer(this);
timer->setInterval(1000);
connect(timer, SIGNAL(timeout()), this, SLOT(updateTime()));
connect(button, SIGNAL(clicked()), timer, SLOT(start()));
void MyWindow::updateTime()
{
timeEdit->setTime(QTime::currentTime());
}
scorpiondezer
1st July 2008, 16:22
Thank you your code is perfect, but you use a current time, can I begin by the initialize time in QTimeEdit
Of course, refer to QTimeEdit and QTime documentations how to get/set the current time of QTimeEdit and how to add time to an existing QTime object.
scorpiondezer
1st July 2008, 17:16
Thank you very much.
The problem resolved
void Window::updateTime()
{
m_s++;
if (m_s>59)
{
m_s=0;
m_m++;
}
if (m_m>59)
{
m_m=0;
m_h++;
}
timeEdit->setTime(QTime(m_h, m_m, m_s));
}
Don't you think using QTime::addSecs() would be easier? ;)
scorpiondezer
1st July 2008, 17:45
yeees good idea, thank you very much:)
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.