在我的一个项目中,我正在使用QTimer,我想知道是否有可能获得QTimer的剩余时间以便让用户知道"下次超时的时间:10秒"或类似的东西......是那可能吗?如果不是这样,有没有关于如何实现这一点的好主意?
也许我要写自己的Timer ...
这是你想要的 ?QTimer :: elapsed()使用计算机时钟,因此根据您的平台,精度会有所不同.
class MyTimer : QTimer
{
MyTimer(QObject* parent) : QTimer(parent)
{
connect(this, timeout(), this, resettime());
}
int start()
{
m_time.start();
return QTimer::start();
}
int start(int msec)
{
m_time.start();
return QTimer::start(msec)l
}
int timeLeft()
{
return interval()-m_time.elapsed()
}
private slots:
void resettime()
{
m_time.restart();
}
private:
QTime m_time;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8295 次 |
| 最近记录: |