#include <QtCore>class SleepThread : public QThread{public: SleepThread(QObject *parent = 0) : QThread(parent) { } ~SleepThread() { }protected: void run() { str = "1\t2\t1 000\t14 000\t15 000\t16 000\t17 000\t50 000\t100 000\t"; qDebug() << str << endl; str.clear(); for (int i = 0; i < 20; ++i) { testUSleep(1); testUSleep(2); testUSleep(1000); testUSleep(14000); testUSleep(15000); testUSleep(16000); testUSleep(17000); testUSleep(50000); testUSleep(100000); qDebug() << str << endl; str.clear(); } }private: QString str; QTime t1, t2; void testUSleep(int t) { t1 = QTime::currentTime(); usleep(t); t2 = QTime::currentTime(); str += QString::number(t1.msecsTo(t2)) + "\t"; }};int main(int argc, char *argv[]){ QCoreApplication a(argc, argv); SleepThread sleeper; sleeper.start(QThread::TimeCriticalPriority); sleeper.wait(); return a.exec();}
"1 2 1 000 14 000 15 000 16 000 17 000 50 000 100 000 " "0 0 0 15 32 15 16 47 109 " "0 0 0 16 15 16 16 62 94 " "0 15 0 16 16 15 16 47 109 " "0 0 0 16 15 32 15 47 110 " "0 0 0 15 16 15 16 63 93 " "0 0 16 16 15 16 15 47 110 " "0 0 0 15 16 16 31 47 93 " "16 0 0 16 15 16 16 62 94 " "0 0 0 15 32 15 16 47 109 " "0 0 0 16 15 16 16 62 94 " "0 16 0 15 16 15 16 47 109 " "0 0 0 16 16 31 15 47 110 " "0 0 0 15 16 16 15 63 93 " "0 0 16 16 15 16 16 46 110 " "0 0 0 15 16 16 31 47 94 " "15 0 0 16 15 16 16 62 94 " "0 0 0 16 31 15 16 47 109 " "0 0 0 16 16 15 16 62 94 " "0 16 0 15 16 16 15 47 109 " "0 0 0 16 16 31 16 46 110 "
QTime t_time;for(;t_time<elapsed(1000);){qApp->processEvents();}