Use QLabel::pixmap()'s non-deprecated by-value form on Qt5

#824 read the pixmap through the pointer overload, which Qt 5.15
deprecates, so the fix it introduced compiled with two deprecation
warnings of its own. Qt 5.15 offers the by-value form behind
Qt::ReturnByValue, so both branches can take the same overload and the
difference reduces to the argument.

Equivalent: the pointer overload returns nullptr when no pixmap is set,
which the old expression turned into a null QPixmap; pixmap(
Qt::ReturnByValue) returns a null QPixmap directly. It also drops the
null check, so the Qt5 branch is now a single expression.

Verified both arms of the #if, since a preprocessor-branched change is
only half tested otherwise:

 - Qt 5.15.18: deprecation warnings for this file 2 -> 0, builds clean,
   binary runs
 - Qt 6.10.2: builds clean, 488/488, links
 - 22 example projects load and export with no crash or hang

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
ispyisail
2026-09-10 16:50:49 +12:00
parent 957bbe5edb
commit 85f46f2b48
+4 -1
View File
@@ -66,8 +66,11 @@ ClickableImageLabel::ClickableImageLabel(const QImage &sourceImage, QWidget *par
void ClickableImageLabel::mousePressEvent(QMouseEvent *event)
{
// QLabel::pixmap() returns a pointer in Qt5 and a value in Qt6.
// Qt 5.15 offers the by-value form behind Qt::ReturnByValue; the
// pointer overload is deprecated there, so take the by-value one
// on both and the difference reduces to the argument.
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
const QPixmap label_pixmap = pixmap() ? *pixmap() : QPixmap();
const QPixmap label_pixmap = pixmap(Qt::ReturnByValue);
#else
const QPixmap label_pixmap = pixmap();
#endif