Skip to content

Commit 8acf99a

Browse files
committed
fix: Process crash caused by closing the application.
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
1 parent 32a8c47 commit 8acf99a

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/mainwidget.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,17 @@ MainWidget::~MainWidget()
5050
{
5151
//程序即将结束,线程标志结束
5252
m_isEndThread = 0;
53+
// 等待线程结束
54+
if (m_loadImagethread) {
55+
m_loadImagethread->requestInterruption(); // 请求线程中断
56+
if (!m_loadImagethread->wait(3000)) { // 等待线程结束,超时时间为3秒
57+
qWarning() << "OCR thread TIMEOUT";
58+
m_loadImagethread->terminate(); // 如果线程没有结束,强制终止线程
59+
m_loadImagethread->deleteLater(); // 删除线程对象
60+
m_loadImagethread = nullptr;
61+
}
62+
// 正常结束的情况下delete操作在槽函数中执行
63+
}
5364
}
5465

5566
void MainWidget::setupUi(QWidget *Widget)

0 commit comments

Comments
 (0)