fix: Null pointer exception for ImageView.#73
Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:release/1050U2from Oct 9, 2025
Merged
fix: Null pointer exception for ImageView.#73deepin-bot[bot] merged 1 commit intolinuxdeepin:release/1050U2from
deepin-bot[bot] merged 1 commit intolinuxdeepin:release/1050U2from
Conversation
When using QTimer for delayed execution, it is necessary to check for null pointers to avoid null pointer exceptions. fix: ImageView空指针异常。 使用QTimer延迟执行时,需要判断空指针,避免空指针异常。 Bug: https://pms.uniontech.com/bug-view-334545.html
max-lvs
approved these changes
Oct 9, 2025
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: lichaofan2008, max-lvs 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) |
02fb3d8
into
linuxdeepin:release/1050U2
4 of 5 checks passed
deepin pr auto review这段代码的审查意见如下:
改进建议代码: void MainWidget::openImage(const QImage &img, const QString &name)
{
// ... 其他代码 ...
if (m_imageview) {
m_imageview->openFilterImage(img);
// 使用 QPointer 安全地访问对象
QPointer<ImageView> imageViewPtr(m_imageview);
QTimer::singleShot(100, [this, imageViewPtr]() {
if (imageViewPtr.isNull()) {
qWarning() << "ImageView object was destroyed before processing";
return;
}
// 处理图像大小调整逻辑
adjustImageViewSize(imageViewPtr);
});
}
}
void MainWidget::adjustImageViewSize(QPointer<ImageView> imageView)
{
if (!imageView || imageView.isNull()) {
return;
}
const QRect imageRect = imageView->image().rect();
const int viewWidth = imageView->width();
const int viewHeight = imageView->height();
if (viewWidth <= 0 || viewHeight <= 0) {
qWarning() << "Invalid view dimensions";
return;
}
// 判断是否需要适应窗口大小
const bool shouldFitToWindow = (imageRect.width() >= viewWidth ||
imageRect.height() >= viewHeight - 150);
if (shouldFitToWindow) {
// 适应窗口大小的逻辑
// ...
} else {
// 适应图片大小的逻辑
// ...
}
}这样的改进提高了代码的安全性、可读性和可维护性,同时减少了潜在的性能问题和崩溃风险。 |
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 using QTimer for delayed execution, it is necessary to check for null pointers to avoid null pointer exceptions.
fix: ImageView空指针异常。
使用QTimer延迟执行时,需要判断空指针,避免空指针异常。
Bug: https://pms.uniontech.com/bug-view-334545.html