开发者

Qt - QTimeEdit as a timer viewer

开发者 https://www.devze.com 2023-01-03 14:47 出处:网络
I have a QTimeEdit which I want to set to some value and the each second I want to decrease by 1 the value that shows the QTimeEdit. So开发者_开发问答 when it will be 0, the I want to have a QMeesageB

I have a QTimeEdit which I want to set to some value and the each second I want to decrease by 1 the value that shows the QTimeEdit. So开发者_开发问答 when it will be 0, the I want to have a QMeesageBox that says "Your time is off.". Can I some how do this with QTimeEdit interface, or I should use QTimer?


You can use QTimeEdit for displaying the time but you will have to use QTimer to decrease the time every second.

You can do something like this:

timeEdit->setTime(...); //set initial time
QTimer timer;
timer.start(1000); //timer will emit timeout() every second
connect(&timer, SIGNAL(timeout()), this, SLOT(slotTimeout()));

void slotTimeout()
{
    QTime time = timeEdit->time().addSecs(-1);
    timeEdit->setTime(time);

    if (time == QTime(0, 0))
        //time is zero, show message box
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号