From 9c3a3ec7912b80afd9fe9049e138c348ecd47a9d 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 | 4 ++++ qtservice/examples/server/main.cpp | 12 ++++++++++-- qtservice/src/qtservice.cpp | 2 +- qtservice/src/qtservice_win.cpp | 11 +++++++++-- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/qtservice/examples/interactive/main.cpp b/qtservice/examples/interactive/main.cpp index d4858b19..3c3891b1 100644 --- a/qtservice/examples/interactive/main.cpp +++ b/qtservice/examples/interactive/main.cpp @@ -39,7 +39,9 @@ ****************************************************************************/ #include +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) #include +#endif #include #include #include @@ -87,7 +89,9 @@ void InteractiveService::start() 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()); +#endif gui->show(); } diff --git a/qtservice/examples/server/main.cpp b/qtservice/examples/server/main.cpp index ebcc218e..4cbf4161 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,13 @@ 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_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)) {