Port to Qt6 (v2)
cover Port to Qt6 (v2)
From: Andres Salomon <[email protected]>
A few years ago, Jonah send patches to port Phonesim to Qt6, but only some of them were accepted. In particular, the patches to convert the project to CMake were not pulled in. Rather than switch to CMake, here's a patch set that enables Qt6 within the existing Autoconf build system.
This first checks for Qt6, and will fall back to Qt5. There are still plenty of warnings when building for Qt6 due to the Qt5 Compat module being used, but those can be cleaned up in time.
Andres Salomon (2):
Only call QTextStream::setCodec in Qt5
Make configure script detect and enable Qt6 if available
Jonah Brüchert (1):
Fix compatibility with Qt6
configure.ac | 26 +++++++++++++++++--------- src/control.cpp | 8 +++++--- src/phonesim.cpp | 2 +- src/qwsppdu.cpp | 12 ++++++------ 4 files changed, 29 insertions(+), 19 deletions(-)
Signature · 1 line
2.51.0
PATCH 1/3 Fix compatibility with Qt6
From: =?UTF-8?q?Jonah=20Br=C3=BCchert?= <[email protected]>
--- src/control.cpp | 6 +++--- src/phonesim.cpp | 2 +- src/qwsppdu.cpp | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-)
src/control.cpp +3 -3
@@ -337,7 +337,7 @@ void ControlWidget::sendSMSMessage() return; } - if (ui->leSMSServiceCenter->text().isEmpty() || ui->leSMSServiceCenter->text().contains(QRegExp("\\D"))) { + if (ui->leSMSServiceCenter->text().isEmpty() || ui->leSMSServiceCenter->text().contains(QRegularExpression(R"(\D)"))) { p->warning(tr("Invalid Service Center"), tr("Service Center must not be empty and contain " "only digits"));
@@ -386,14 +386,14 @@ void ControlWidget::selectFile() void ControlWidget::sendSMSDatagram() { QString dstPortStr = ui->leDstPort->text(); - if ( dstPortStr.contains(QRegExp("\\D")) ) { + if ( dstPortStr.contains(QRegularExpression(R"(\D)")) ) { p->warning(tr("Invalid Port"), tr("Port number can contain only digits" )); return; } int dst = dstPortStr.toInt(); QString srcPortStr = ui->leSrcPort->text(); - if ( srcPortStr.contains(QRegExp("\\D")) ) { + if ( srcPortStr.contains(QRegularExpression(R"(\D)")) ) { p->warning(tr("Invalid Port"), tr("Port number can contain only digits" )); return; }
src/phonesim.cpp +1 -1
@@ -346,7 +346,7 @@ bool SimChat::command( const QString& cmd ) else { int index = value.indexOf( "${*}" ); if ( index != -1 ) { - if ( wild.length() > 0 && wild[wild.length() - 1] == 0x1A ) { + if ( wild.length() > 0 && wild[wild.length() - 1] == QChar(0x1A) ) { // Strip the terminating ^Z from SMS PDU's. wild = wild.left( wild.length() - 1 ); }
src/qwsppdu.cpp +6 -6
@@ -707,7 +707,7 @@ QString QWspPduDecoder::decodeTextString() if (o == '\"') o = decodeOctet(); while (o != 0 && !dev->atEnd()) { - str += o; + str += QChar(o); o = decodeOctet(); }
@@ -722,7 +722,7 @@ QString QWspPduDecoder::decodeTextBlock(int length) { QString result; for(int i = 0; i < length; ++i) - result += decodeOctet(); + result += QChar(decodeOctet()); return result; }
@@ -815,7 +815,7 @@ QString QWspPduDecoder::decodeContentType() // Extension-Media o = decodeOctet(); while (o != 0) { - type += o; + type += QChar(o); o = decodeOctet(); } }
@@ -838,7 +838,7 @@ QString QWspPduDecoder::decodeContentType() // Constrained-encoding = Extension-Media o = decodeOctet(); while (o != 0) { - type += o; + type += QChar(o); o = decodeOctet(); } }
@@ -988,13 +988,13 @@ QString QWspPduDecoder::decodeParameter() p = decodeTokenText() + "="; octet = peekOctet(); if (octet <= 31 || octet & 0x80) { - p += decodeInteger(); + p += QChar(decodeInteger()); } else { // Extension-Media p += '\"'; octet = decodeOctet(); while (octet != 0 && !dev->atEnd()) { - p += octet; + p += QChar(octet); octet = decodeOctet(); } p += '\"';
Signature · 1 line
2.51.0
PATCH 2/3 Only call QTextStream::setCodec in Qt5
In reply to Andres SalomonFrom: Andres Salomon <[email protected]>
Qt6 defaults to UTF8, and setCodec was removed.
--- src/control.cpp | 2 ++ 1 file changed, 2 insertions(+)
src/control.cpp +2 -0
@@ -700,7 +700,9 @@ QString Script::Run(const QString &name, const QDBusMessage &msg) } QTextStream stream(&scriptFile); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) stream.setCodec("UTF-8"); +#endif QString contents = stream.readAll(); scriptFile.close();
Signature · 1 line
2.51.0
PATCH 3/3 Make configure script detect and enable Qt6 if available
In reply to Andres SalomonFrom: Andres Salomon <[email protected]>
We also bump the C++ standard up to C++17.
--- configure.ac | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-)
configure.ac +17 -9
@@ -26,17 +26,25 @@ AC_ARG_ENABLE(optimization, AS_HELP_STRING([--disable-optimization], fi ]) -PKG_CHECK_MODULES(QT, Qt5Core Qt5Gui Qt5Xml Qt5Network Qt5Qml Qt5DBus [Qt5Widgets >= 5.10], - dummy=yes, AC_MSG_ERROR(Qt5 is required)) +PKG_CHECK_MODULES(QT6, Qt6Core Qt6Gui Qt6Xml Qt6Network Qt6Qml Qt6DBus Qt6Core5Compat [Qt6Widgets >= 6.0.0], AC_SUBST(QT6_ENABLED, "yes"), + [PKG_CHECK_MODULES(QT5, Qt5Core Qt5Gui Qt5Xml Qt5Network Qt5Qml Qt5DBus [Qt5Widgets >= 5.10], dummy=yes, AC_MSG_ERROR(Qt5 is required))] +) # Needed for qOverload -CXXFLAGS="$CXXFLAGS --std=gnu++14" - -AC_SUBST(QT_CFLAGS) -AC_SUBST(QT_LIBS) - -AC_MSG_CHECKING(for Qt5 host_bins) -PKG_CHECK_VAR(QMAKE_PATH_HOST_BINS, Qt5Core, host_bins) +CXXFLAGS="$CXXFLAGS --std=gnu++17" + +AC_SUBST(QT_CFLAGS, "${QT5_CFLAGS} ${QT6_CFLAGS}") +AC_SUBST(QT_LIBS, "${QT6_LIBS} ${QT5_LIBS}") + +AS_IF([test "x$QT6_ENABLED" = "xyes"], [ + # Try for Qt6 + AC_MSG_CHECKING(for Qt6 host_bins) + PKG_CHECK_VAR(QMAKE_PATH_HOST_BINS, Qt6Core, libexecdir) +], [ + # Try for Qt5 + AC_MSG_CHECKING(for Qt5 host_bins) + PKG_CHECK_VAR(QMAKE_PATH_HOST_BINS, Qt5Core, host_bins) +]) AC_SUBST(QMAKE_PATH_HOST_BINS) AC_MSG_RESULT($QMAKE_PATH_HOST_BINS)
Signature · 1 line
2.51.0