首页 > 代码库 > QT延时方法整理(QTimer::singleShot,QWaitCondition,QDateTime.secsTo三种新方法)

QT延时方法整理(QTimer::singleShot,QWaitCondition,QDateTime.secsTo三种新方法)

1:

void QTimer::singleShot ( int msec, QObject * receiver, const char * member ) [static]   

样例:

 #include <QApplication>

 #include <QTimer>

 int main(int argc, char *argv[])

 {

  QApplication app(argc, argv);

  QTimer::singleShot(600000, &app, SLOT(quit()));

  ...

  return app.exec();

 }

 

2:

QWaitCondition waitCond;

waitCond.wait (400); // or any other time in [ms]

 

3:

QDateTime n2=QDateTime::currentDateTime();

  QDateTime now;

  do{

      now=QDateTime::currentDateTime();

  } while (n2.secsTo(now)<=6);  //6为需要延时的秒数

 

http://blog.csdn.net/liuguangzhou123/article/details/7399253

QT延时方法整理(QTimer::singleShot,QWaitCondition,QDateTime.secsTo三种新方法)