下面是一个利用QTime实现的简单的延时程序,本来想利用QTimer实现的,但总是不成功,哪位高手知道的话,还请赐教!
#include<QApplication>
#include<QtGui>
#include<QTimer>
#include<QTime>
#include<QString>
#include<iostream>
using namespace std;
void killtime(const int tt)
{
QTime a;
a.start();
while(a.elapsed()<tt *1000)
;
return;
}
int main(int argc,char *argv[])
{
QApplication app(argc,argv);
QTime a;
QString curtime = a.currentTime().toString("hh:mm::ss");
cout<<qPrintable(curtime)<<endl;
#if 0
/*
QTimer *timer = new QTimer;
timer->setSingleShot(true);
timer->start(10*1000);
*/
timer->singleShot(10*1000,&app,SLOT(quit()));
while(timer->isActive())
{
curtime = QTime::currentTime().toString("hh:mm::ss");
cout<<qPrintable(curtime)<<endl;
}
#endif
killtime(5);
curtime = a.currentTime().toString("hh:mm::ss");
cout<<qPrintable(curtime)<<endl;
return app.exec();
}
|
阅读(2030) | 评论(0) | 转发(0) |