From 9c296488e496328a27c570af728a3d69938a2581 Mon Sep 17 00:00:00 2001 From: Sergey Fedorov Date: Tue, 11 Aug 2026 07:01:13 +0000 Subject: [PATCH 4/4] Guard two more Qt5-only APIs found by an exhaustive audit QPixmap::setDevicePixelRatio() is Qt5.1: mylabelpreviewer.cpp:58: error: 'class QPixmap' has no member named 'setDevicePixelRatio' Skipping it on Qt4 is a no-op, not a behavior change: globals::scaleFactor() already returns a hardcoded 1.0 there, and setting a ratio of 1.0 does nothing. QNetworkRequest::RedirectPolicyAttribute is Qt5.9. Without it the update check would have compiled but silently stopped working, since onNetworkReply() only handles HTTP 200 and would ignore the 30x. Qt4 therefore follows the redirect by hand via RedirectionTargetAttribute (Qt4.7), resolved against the reply URL so relative targets work, with a five hop limit to bound redirect loops. Both were missed earlier by pattern-based greps: setDevicePixelRatio does not match a case-sensitive search for "devicePixelRatio", and RedirectPolicyAttribute is an enumerator rather than a class or method name. This pass instead extracted every method call, enum reference and type name in the tree and checked each against Qt4: 500 method names, 46 enum references, 87 types, plus free functions, macros, SIGNAL/SLOT names and .ui connections. Nothing else remains. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01PYgCCiu49ZE7W7TqTdxhBi --- src/mylabelpreviewer.cpp | 4 ++++ src/updatechecker.cpp | 26 ++++++++++++++++++++++++++ src/updatechecker.h | 1 + 3 files changed, 31 insertions(+) diff --git a/src/mylabelpreviewer.cpp b/src/mylabelpreviewer.cpp index 0358645..949c569 100755 --- a/src/mylabelpreviewer.cpp +++ b/src/mylabelpreviewer.cpp @@ -55,7 +55,11 @@ void myLabelPreviewer::showPreview(QImage thumbnail, int orig_w, int orig_h, dou else { QPixmap pixmap = QPixmap::fromImage(thumbnail); pixmap = pixmap.scaled(QSize(320, 240) * m_scaleFactor, Qt::KeepAspectRatio, Qt::SmoothTransformation); +#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0) + // Qt4 has no HiDPI support, and globals::scaleFactor() is always 1.0 + // there, so skipping this is a no-op rather than a behavior change. pixmap.setDevicePixelRatio(m_scaleFactor); +#endif this->setPixmap(pixmap); } diff --git a/src/updatechecker.cpp b/src/updatechecker.cpp index e37ee98..2de90a9 100755 --- a/src/updatechecker.cpp +++ b/src/updatechecker.cpp @@ -32,6 +32,7 @@ UpdateChecker::UpdateChecker(QObject *parent) : QObject(parent) { m_update_available = false; + m_redirectCount = 0; mNetworkManager = new QNetworkAccessManager(this); QObject::connect(mNetworkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(onNetworkReply(QNetworkReply*))); @@ -41,7 +42,12 @@ void UpdateChecker::checkForUpdates() { QUrl url(VERSION_URL); QNetworkRequest netReq(url); + + m_redirectCount = 0; + +#if QT_VERSION >= QT_VERSION_CHECK(5, 9, 0) netReq.setAttribute(QNetworkRequest::RedirectPolicyAttribute, true); // Autoredirect +#endif mNetworkManager->get(netReq); } @@ -56,6 +62,26 @@ void UpdateChecker::onNetworkReply(QNetworkReply* reply) QString replyString; if(reply->error() == QNetworkReply::NoError) { +#if QT_VERSION < QT_VERSION_CHECK(5, 9, 0) + /* + * RedirectPolicyAttribute is Qt5.9, so before that the redirect has to + * be followed by hand or the reply is just a 30x the switch below + * ignores. The hop limit keeps a redirect loop from spinning forever. + */ + const QVariant redirectTarget = + reply->attribute(QNetworkRequest::RedirectionTargetAttribute); + + if (redirectTarget.isValid() && m_redirectCount < 5) { + const QUrl target = reply->url().resolved(redirectTarget.toUrl()); + + m_redirectCount++; + mNetworkManager->get(QNetworkRequest(target)); + + reply->deleteLater(); + return; + } +#endif + int httpstatuscode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toUInt(); //qDebug() << "httpstatuscode: " << httpstatuscode; diff --git a/src/updatechecker.h b/src/updatechecker.h index 96f8438..bb09fda 100755 --- a/src/updatechecker.h +++ b/src/updatechecker.h @@ -45,6 +45,7 @@ private: QNetworkAccessManager* mNetworkManager; bool m_update_available; + int m_redirectCount; // Only consulted when redirects are followed by hand (Qt < 5.9) private slots: void onNetworkReply(QNetworkReply* reply);