我正在尝试在我的Qt应用程序中处理某些内容时显示一个带有消息的窗口,因此我决定使用QProgressDialog
。
但我有问题,文字标签没有显示: QProgressDialog not showing the text label
我的代码:
QProgressDialog progressDialog(this);
progressDialog.setWindowTitle("Cargando");
progressDialog.setLabelText("Cargando los datos del volumen, por favor espere");
progressDialog.setCancelButton(0);
progressDialog.show();
// DOING SOME STUFF
progressDialog.close();
我意识到,如果我使用progressDialog.exec()
而不是progressDialog.show()
,则会显示文本标签,但应用程序会被阻止。
有人可以帮助我吗?
答案 0 :(得分:0)
The reason your dialog isn't showing anything is probably because of your `DOING SOME STUFF. If you are doing this stuff on the main thread, it will block your UI -and the dialog from drawing it's contents.
Depending on what this stuff is, you have 2 options:
If you are doing something in a loop, just call QApplication::processEvents
on every iteration.
If the operations themselve take longer or it's not a loop, you will have to execute this stuff asynchronously, on a different thread. For example, by using QtConcurrent::run
. Use a QFutureWatcher
to close the dialog once the concurrent operation finished