From bcbc652dc63c4c663f9d2c17bb60daea5e400961 Mon Sep 17 00:00:00 2001 From: lichaofan Date: Thu, 9 Oct 2025 16:38:11 +0800 Subject: [PATCH] fix: Null pointer exception for ImageView. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/mainwidget.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/mainwidget.cpp b/src/mainwidget.cpp index 6656008..dd4931a 100644 --- a/src/mainwidget.cpp +++ b/src/mainwidget.cpp @@ -377,7 +377,14 @@ void MainWidget::openImage(const QImage &img, const QString &name) setIcons(themeType); if (m_imageview) { m_imageview->openFilterImage(img); + // 使用 QPointer 检查对象是否还存在 + QPointer imgSelf(m_imageview); QTimer::singleShot(100, [ = ] { + if (imgSelf.isNull()) { + qWarning() << "ImageView obj is destroyed"; + return; // 对象已被销毁 + } + //分辨率大于window的采用适应窗口,没超过,则适应图片 QRect rect1 = m_imageview->image().rect(); if ((rect1.width() >= m_imageview->width() || rect1.height() >= m_imageview->height() - 150) && m_imageview->width() > 0 &&