From 8acf99a4beb5ad9b878a2fa3ed49be038ccde44b Mon Sep 17 00:00:00 2001 From: lichaofan Date: Mon, 22 Sep 2025 11:29:14 +0800 Subject: [PATCH] fix: Process crash caused by closing the application. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When performing the destruction operation, it is necessary to wait for the child thread to exit to avoid errors in resource release. fix: 关闭应用引起进程崩溃 析构操作时,需要等待子线程退出,避免资源释放出错。 Bug: https://pms.uniontech.com/bug-view-334545.html --- src/mainwidget.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/mainwidget.cpp b/src/mainwidget.cpp index 911abbad..18560619 100644 --- a/src/mainwidget.cpp +++ b/src/mainwidget.cpp @@ -50,6 +50,17 @@ MainWidget::~MainWidget() { //程序即将结束,线程标志结束 m_isEndThread = 0; + // 等待线程结束 + if (m_loadImagethread) { + m_loadImagethread->requestInterruption(); // 请求线程中断 + if (!m_loadImagethread->wait(3000)) { // 等待线程结束,超时时间为3秒 + qWarning() << "OCR thread TIMEOUT"; + m_loadImagethread->terminate(); // 如果线程没有结束,强制终止线程 + m_loadImagethread->deleteLater(); // 删除线程对象 + m_loadImagethread = nullptr; + } + // 正常结束的情况下delete操作在槽函数中执行 + } } void MainWidget::setupUi(QWidget *Widget)