From 63d2de1a9e8e59fbd46f244359cf0f798128f48b Mon Sep 17 00:00:00 2001 From: Sergey Fedorov Date: Wed, 12 Aug 2026 19:17:46 +0000 Subject: [PATCH] Qt4: replace QStringLiteral, setCurrentText, QLatin1String::contains, RedirectPolicyAttribute Four more Qt5+-only APIs surfaced by the build: - QStringLiteral: the macro itself doesn't exist before Qt5.0. Replaced with QLatin1String, which is functionally equivalent for a literal and has existed since Qt4. - QComboBox::setCurrentText(): added in Qt 5.0. All 3 call sites follow reload_settings(), which just repopulated the combo box with the name being selected, so setCurrentIndex(findText(name)) is the direct Qt4-compatible equivalent -- same semantics for this case. - QLatin1String::contains(): Qt4's QLatin1String is a much thinner wrapper and only grew convenience methods like contains() over Qt5's lifetime (added 5.9). Convert to QString::fromLatin1(...) first, which has had contains() forever. - QNetworkRequest::RedirectPolicyAttribute / ManualRedirectPolicy: the enum values were added in Qt 5.9, the same release that's needed for it to matter -- QNetworkAccessManager only started auto-following redirects by default in Qt 5.6+. Older Qt (including Qt4) never auto-follows, so manual is already the effective behavior without this attribute; version-gated behind Qt 5.9 rather than removed, to keep the Qt6 build's behavior unchanged. --- src/dialog/mainwindow.cpp | 26 ++++++++++++++++---------- src/vpninfo.cpp | 2 +- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/dialog/mainwindow.cpp b/src/dialog/mainwindow.cpp index eef1742..28eca96 100644 --- a/src/dialog/mainwindow.cpp +++ b/src/dialog/mainwindow.cpp @@ -176,7 +176,7 @@ MainWindow::MainWindow(QWidget* parent, bool useTray, const QString profileName) connect(m_trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason))); - m_trayIcon->setIcon(platformTrayIcon(QStringLiteral(":/images/network-disconnected.png"))); + m_trayIcon->setIcon(platformTrayIcon(QLatin1String(":/images/network-disconnected.png"))); m_trayIcon->show(); } else { Logger::instance().addMessage(QLatin1String("System doesn't support tray icon")); @@ -476,7 +476,13 @@ void MainWindow::checkLatestVersion() const { QNetworkRequest req(QUrl(GITLAB_LATEST_RELEASE_URL)); +#if QT_VERSION >= QT_VERSION_CHECK(5, 9, 0) + /* Only needed from Qt 5.9, which is also when QNetworkAccessManager + * started auto-following redirects by default (Qt 5.6+); older Qt + * (including Qt4) never auto-follows, so manual is already the + * effective behavior without this attribute. */ req.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::ManualRedirectPolicy); +#endif connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(gotLatestVersion(QNetworkReply*))); @@ -629,7 +635,7 @@ void MainWindow::changeStatus(int val) ui->connectionButton->setText(tr("Disconnect")); if (m_trayIcon) { - m_trayIcon->setIcon(platformTrayIcon(QStringLiteral(":/images/network-connected.png"))); + m_trayIcon->setIcon(platformTrayIcon(QLatin1String(":/images/network-connected.png"))); } this->ui->ipV4Label->setText(ip); @@ -657,7 +663,7 @@ void MainWindow::changeStatus(int val) } else if (val == STATUS_CONNECTING) { if (m_trayIcon) { - m_trayIcon->setIcon(platformTrayIcon(QStringLiteral(":/images/network-disconnected.png"))); + m_trayIcon->setIcon(platformTrayIcon(QLatin1String(":/images/network-disconnected.png"))); m_trayIcon->setToolTip(QLatin1String("Connecting to ") + ui->serverList->currentText()); } @@ -707,7 +713,7 @@ void MainWindow::changeStatus(int val) ui->connectionButton->setText(tr("Connect")); if (m_trayIcon) { - m_trayIcon->setIcon(platformTrayIcon(QStringLiteral(":/images/network-disconnected.png"))); + m_trayIcon->setIcon(platformTrayIcon(QLatin1String(":/images/network-disconnected.png"))); if (this->isHidden() == true) m_trayIcon->showMessage(QLatin1String("Disconnected"), QLatin1String("You were disconnected from the VPN"), @@ -888,7 +894,7 @@ void MainWindow::on_connectClicked() /* ss is now deallocated by vpninfo */ try { - vpninfo = new VpnInfo(QStringLiteral("AnyConnect-compatible OpenConnect GUI VPN Agent"), ss, this); + vpninfo = new VpnInfo(QLatin1String("AnyConnect-compatible OpenConnect GUI VPN Agent"), ss, this); } catch (std::exception& ex) { QMessageBox::information(this, qApp->applicationName(), @@ -1114,7 +1120,7 @@ void MainWindow::on_actionNewProfile_triggered() } reload_settings(); - ui->serverList->setCurrentText(dialog.getNewProfileName()); + ui->serverList->setCurrentIndex(ui->serverList->findText(dialog.getNewProfileName())); } void MainWindow::on_actionNewProfileAdvanced_triggered() @@ -1126,7 +1132,7 @@ void MainWindow::on_actionNewProfileAdvanced_triggered() } reload_settings(); - ui->serverList->setCurrentText(dialog.getEditedProfileName()); + ui->serverList->setCurrentIndex(ui->serverList->findText(dialog.getEditedProfileName())); } void MainWindow::on_actionEditSelectedProfile_triggered() @@ -1137,7 +1143,7 @@ void MainWindow::on_actionEditSelectedProfile_triggered() } reload_settings(); - ui->serverList->setCurrentText(dialog.getEditedProfileName()); + ui->serverList->setCurrentIndex(ui->serverList->findText(dialog.getEditedProfileName())); } #define PREFIX "server:" // LCA: remote this... @@ -1167,7 +1173,7 @@ void MainWindow::on_actionAbout_triggered() { QString txt = QLatin1String("

") + QLatin1String(PRODUCT_NAME_LONG) + QLatin1String("

"); - if (QLatin1String(PROJECT_VERSION).contains(QLatin1String("-g"))) { + if (QString::fromLatin1(PROJECT_VERSION).contains(QLatin1String("-g"))) { txt += tr("Development snapshot %1 (%2 bit)
").arg(PROJECT_VERSION).arg(sizeof(void*) == 4 ? 32 : 64); txt += tr("Built at %1
").arg(QLatin1String(appBuildOn)); } else { @@ -1200,7 +1206,7 @@ void MainWindow::checkForUpdatesDialog() QString txt = QLatin1String("

") + QLatin1String(PRODUCT_NAME_LONG) + QLatin1String("

"); txt += tr("

Current version

"); - if (QLatin1String(PROJECT_VERSION).contains(QLatin1String("-g"))) { + if (QString::fromLatin1(PROJECT_VERSION).contains(QLatin1String("-g"))) { txt += tr("Development snapshot %1 (%2 bit)
").arg(PROJECT_VERSION).arg(sizeof(void*) == 4 ? 32 : 64); txt += tr("Built at %1
").arg(QLatin1String(appBuildOn)); } else { diff --git a/src/vpninfo.cpp b/src/vpninfo.cpp index 62cd06c..7f8439e 100644 --- a/src/vpninfo.cpp +++ b/src/vpninfo.cpp @@ -502,7 +502,7 @@ void VpnInfo::setUrl(const QUrl& url) this->mUrl = url; if (mUrl.scheme().isEmpty()) { - mUrl.setScheme(QStringLiteral("https")); + mUrl.setScheme(QLatin1String("https")); } openconnect_parse_url(this->vpninfo, mUrl.url().toUtf8().constData()); -- 2.43.0