在线程中使用延时2ms,打印出来却是20多毫秒,弹出QMessagebox阻塞主界面后延时又正常,不知道什么原因,代码如下:
void MainWindow::on_pushButton_clicked()
{
std::thread th(&MainWindow::test,this);
th.detach();
}
void MainWindow::test()
{
int i = 0;
while (i<3000)
{
QTime a = QTime::currentTime();
QThread::msleep(2);
QTime b = QTime::currentTime();
qDebug()<<a.msecsTo(b);
i++;
}
}
void MainWindow::on_pushButton_2_clicked()
{
qDebug()<<"QMessageBox Pop";
QMessageBox::information(this,"11","11");
}
输出如下
16
27
26
27
16
26
27
26
27
28
QMessageBox Pop
3
3
3
3
2
2
3
3
3
3
3
3
3