From b93d665bf4c03555e683754e370c198f708e3938 Mon Sep 17 00:00:00 2001 From: Kang Lin Date: Wed, 16 Feb 2022 15:54:23 +0800 Subject: [PATCH] QtService: support qt6 Change-Id: I1a2aa1cb83e7cbff96ba1d4f3bd2cc7d8c0756cd --- qtservice/examples/interactive/main.cpp | 23 ++++++++++++++++++----- qtservice/examples/server/main.cpp | 11 +++++++++-- qtservice/src/qtservice.cpp | 2 +- qtservice/src/qtservice.h | 2 +- qtservice/src/qtservice_win.cpp | 11 +++++++++-- 5 files changed, 38 insertions(+), 11 deletions(-) diff --git a/qtservice/examples/interactive/main.cpp b/qtservice/examples/interactive/main.cpp index d4858b19..92abf6bf 100644 --- a/qtservice/examples/interactive/main.cpp +++ b/qtservice/examples/interactive/main.cpp @@ -39,7 +39,11 @@ ****************************************************************************/ #include +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) #include +#else +#include +#endif #include #include #include @@ -77,17 +81,26 @@ InteractiveService::~InteractiveService() void InteractiveService::start() { #if defined(Q_OS_WIN) - if ((QSysInfo::WindowsVersion & QSysInfo::WV_NT_based) && - (QSysInfo::WindowsVersion >= QSysInfo::WV_VISTA)) { - logMessage( "Service GUI not allowed on Windows Vista. See the documentation for this example for more information.", QtServiceBase::Error ); - return; - } + #if QT_VERSION < QT_VERSION_CHECK(5, 4, 0) + if ((QSysInfo::WindowsVersion & QSysInfo::WV_NT_based) && + (QSysInfo::WindowsVersion >= QSysInfo::WV_VISTA)) + #else + if (QSysInfo::productVersion().toUInt() >= 8) + #endif + { + logMessage( "Service GUI not allowed on Windows Vista. See the documentation for this example for more information.", QtServiceBase::Error ); + return; + } #endif qApp->setQuitOnLastWindowClosed(false); gui = new QLabel("Service", 0, Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) gui->move(QApplication::desktop()->availableGeometry().topLeft()); +#else + gui->move(QGuiApplication::primaryScreen()->availableGeometry().topLeft()); +#endif gui->show(); } diff --git a/qtservice/examples/server/main.cpp b/qtservice/examples/server/main.cpp index ebcc218e..009579e4 100644 --- a/qtservice/examples/server/main.cpp +++ b/qtservice/examples/server/main.cpp @@ -46,7 +46,9 @@ #include #include #include - +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +#include +#endif #include "qtservice.h" // HttpDaemon is the the class that implements the simple HTTP server. @@ -98,7 +100,12 @@ private slots: // document back. QTcpSocket* socket = (QTcpSocket*)sender(); if (socket->canReadLine()) { - QStringList tokens = QString(socket->readLine()).split(QRegExp("[ \r\n][ \r\n]*")); + QStringList tokens; +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + tokens = QString(socket->readLine()).split(QRegularExpression("[ \r\n][ \r\n]*")); +#else + tokens = QString(socket->readLine()).split(QRegExp("[ \r\n][ \r\n]*")); +#endif if (tokens[0] == "GET") { QTextStream os(socket); os.setAutoDetectUnicode(true); diff --git a/qtservice/src/qtservice.cpp b/qtservice/src/qtservice.cpp index 5eae058e..3374a1e6 100644 --- a/qtservice/src/qtservice.cpp +++ b/qtservice/src/qtservice.cpp @@ -663,7 +663,7 @@ QtServiceBase::QtServiceBase(int argc, char **argv, const QString &name) d_ptr = new QtServiceBasePrivate(nm); d_ptr->q_ptr = this; - d_ptr->serviceFlags = 0; + d_ptr->serviceFlags = static_cast(0); d_ptr->sysd = 0; for (int i = 0; i < argc; ++i) d_ptr->args.append(QString::fromLocal8Bit(argv[i])); diff --git a/qtservice/src/qtservice.h b/qtservice/src/qtservice.h index 01d5b07f..4fb3c3c4 100644 --- a/qtservice/src/qtservice.h +++ b/qtservice/src/qtservice.h @@ -59,7 +59,7 @@ # define QT_QTSERVICE_EXPORT #endif -class QStringList; +//class QStringList; class QtServiceControllerPrivate; class QT_QTSERVICE_EXPORT QtServiceController diff --git a/qtservice/src/qtservice_win.cpp b/qtservice/src/qtservice_win.cpp index e5b7ecc5..3b9a1ae1 100644 --- a/qtservice/src/qtservice_win.cpp +++ b/qtservice/src/qtservice_win.cpp @@ -737,10 +737,17 @@ class QtServiceAppEventFilter : public QAbstractNativeEventFilter { public: QtServiceAppEventFilter() {} - bool nativeEventFilter(const QByteArray &eventType, void *message, long *result); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + virtual bool nativeEventFilter(const QByteArray &eventType, void *message, qintptr *result); +#else + bool nativeEventFilter(const QByteArray &eventType, void *message, long *result) override; +#endif }; - +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +bool QtServiceAppEventFilter::nativeEventFilter(const QByteArray &, void *message, qintptr *result) +#else bool QtServiceAppEventFilter::nativeEventFilter(const QByteArray &, void *message, long *result) +#endif { MSG *winMessage = (MSG*)message; if (winMessage->message == WM_ENDSESSION && (winMessage->lParam & ENDSESSION_LOGOFF)) {