我有一个使用 20 个不同类的应用程序。程序在主窗口中开始执行。我启动一个进度对话框。我将根据不同的目的使用不同的类。在执行转到特定类并执行所需操作并返回到主窗口类的每个函数调用之后,我将更新进度对话框。现在的问题是,当执行脱离主窗口类时,进度对话框会卡住。无法访问取消按钮,因此无法在所需时间停止执行。
主类::主类() {
ProgressDialog->exec();
x->add();
updateProgressDialog();
y->do();
updateProgressDialog();
zz->bring();
updateProgressDialog();
}
//x、y、z 是三个不同的类。
这就是执行的过程。一旦我进入主类中的函数,我就会启动进度对话框。并调用不同类的函数。这些功能需要花费大量时间。我已经调用了一个线程来执行执行部分,但我无法取消进度对话框。我希望当按下进度对话框上的取消按钮时停止程序执行。
请让我知道如何解决这个问题。希望我在这里说清楚了。
最佳答案
如果不确切知道线程中正在执行哪些计算,就很难隔离问题。也许这可以帮助:Keeping the GUI Responsive
Excerpt from: Performing Long Operations (by: Witold Wysota)
During long calculations (regardless of any usage of signals and slots) all event processing gets halted. As a result, the GUI is not refreshed, user input is not processed, network activity stops and timers don't fire—the application looks like it's frozen and, in fact, the part of it not related to the time-intensive task is frozen.
关于QT 进度对话框取消按钮未突出显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3494363/