fix: Process crash caused by closing the application.#72
Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:release/1050U2from Sep 23, 2025
Merged
Conversation
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
deepin pr auto review这段代码是关于线程管理的改进,我来分析一下它的优点和可以改进的地方: 优点:
改进建议:
改进后的代码建议: MainWidget::~MainWidget()
{
// 程序即将结束,线程标志结束
m_isEndThread = 0;
// 等待线程结束
if (m_loadImagethread && m_loadImagethread->isRunning()) {
m_loadImagethread->requestInterruption();
if (!m_loadImagethread->wait(3000)) {
qCritical() << "OCR thread failed to stop gracefully, terminating forcefully";
m_loadImagethread->terminate();
m_loadImagethread->wait(); // 确保线程完全终止
}
}
// 确保线程对象被正确清理
if (m_loadImagethread) {
m_loadImagethread->deleteLater();
m_loadImagethread = nullptr;
}
if (m_mainGridLayout && m_buttonHorizontalLayout) {
m_mainGridLayout->removeItem(m_buttonHorizontalLayout);
}
}
void MainWidget::openImage(const QImage &img, const QString &name)
{
// ... 其他代码 ...
connect(m_loadImagethread, &QThread::finished, [this]() {
QMutexLocker locker(&m_threadMutex); // 确保线程安全
if (m_loadImagethread) {
m_loadImagethread->deleteLater();
m_loadImagethread = nullptr;
}
});
m_loadImagethread->start();
}这些改进可以提高代码的健壮性、安全性和可维护性。 |
lzwind
approved these changes
Sep 23, 2025
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: lichaofan2008, lzwind The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Contributor
Author
|
/forcemerge |
Contributor
|
This pr force merged! (status: unstable) |
35ba262
into
linuxdeepin:release/1050U2
4 of 5 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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