QProgressDialog在initializeGL期间不绘制

时间:2013-06-24 10:02:00

标签: c++ qt progressdialog

我正在使用QProgressDialog来显示initializeGL()功能的进度,但是小窗口显示未上映...这是简化代码:

QProgressDialog barTest("Wait","Ok", 0, 100, this);

barTest.move(400,400);

barTest.show();

for(int i = 0; i < 100; i++)
{
    barTest.setValue(i);
    qDebug() << i;
}

我正在运行Mac OS 10.8

1 个答案:

答案 0 :(得分:1)

问题在于,只要您执行代码(例如for循环),窗口的绘制事件就会卡在Qt的事件循环中。

如果您希望处理绘画事件,可以使用QApplication::processEvents

for(int i = 0; i < 100; i++)
{
    barTest.setValue(i);
    qDebug() << i;

    // handle repaints (but also any other event in the queue)
    QApplication::processEvents();
}

根据循环的快速性,您可能会发现仅更新每个10%就足够了:

for(int i = 0; i < 100; i++)
{
    barTest.setValue(i);
    qDebug() << i;

    // handle repaints (but also any other event in the queue)
    if(i % 10 == 0) QApplication::processEvents();
}
相关问题