Skip to content

Commit b93d665

Browse files
committed
QtService: support qt6
Change-Id: I1a2aa1cb83e7cbff96ba1d4f3bd2cc7d8c0756cd
1 parent 917a3f1 commit b93d665

File tree

5 files changed

+38
-11
lines changed

5 files changed

+38
-11
lines changed

qtservice/examples/interactive/main.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@
3939
****************************************************************************/
4040

4141
#include <QApplication>
42+
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
4243
#include <QDesktopWidget>
44+
#else
45+
#include <QScreen>
46+
#endif
4347
#include <QLabel>
4448
#include <QDir>
4549
#include <QSettings>
@@ -77,17 +81,26 @@ InteractiveService::~InteractiveService()
7781
void InteractiveService::start()
7882
{
7983
#if defined(Q_OS_WIN)
80-
if ((QSysInfo::WindowsVersion & QSysInfo::WV_NT_based) &&
81-
(QSysInfo::WindowsVersion >= QSysInfo::WV_VISTA)) {
82-
logMessage( "Service GUI not allowed on Windows Vista. See the documentation for this example for more information.", QtServiceBase::Error );
83-
return;
84-
}
84+
#if QT_VERSION < QT_VERSION_CHECK(5, 4, 0)
85+
if ((QSysInfo::WindowsVersion & QSysInfo::WV_NT_based) &&
86+
(QSysInfo::WindowsVersion >= QSysInfo::WV_VISTA))
87+
#else
88+
if (QSysInfo::productVersion().toUInt() >= 8)
89+
#endif
90+
{
91+
logMessage( "Service GUI not allowed on Windows Vista. See the documentation for this example for more information.", QtServiceBase::Error );
92+
return;
93+
}
8594
#endif
8695

8796
qApp->setQuitOnLastWindowClosed(false);
8897

8998
gui = new QLabel("Service", 0, Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint);
99+
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
90100
gui->move(QApplication::desktop()->availableGeometry().topLeft());
101+
#else
102+
gui->move(QGuiApplication::primaryScreen()->availableGeometry().topLeft());
103+
#endif
91104
gui->show();
92105
}
93106

qtservice/examples/server/main.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@
4646
#include <QStringList>
4747
#include <QDir>
4848
#include <QSettings>
49-
49+
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
50+
#include <QRegularExpression>
51+
#endif
5052
#include "qtservice.h"
5153

5254
// HttpDaemon is the the class that implements the simple HTTP server.
@@ -98,7 +100,12 @@ private slots:
98100
// document back.
99101
QTcpSocket* socket = (QTcpSocket*)sender();
100102
if (socket->canReadLine()) {
101-
QStringList tokens = QString(socket->readLine()).split(QRegExp("[ \r\n][ \r\n]*"));
103+
QStringList tokens;
104+
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
105+
tokens = QString(socket->readLine()).split(QRegularExpression("[ \r\n][ \r\n]*"));
106+
#else
107+
tokens = QString(socket->readLine()).split(QRegExp("[ \r\n][ \r\n]*"));
108+
#endif
102109
if (tokens[0] == "GET") {
103110
QTextStream os(socket);
104111
os.setAutoDetectUnicode(true);

qtservice/src/qtservice.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ QtServiceBase::QtServiceBase(int argc, char **argv, const QString &name)
663663
d_ptr = new QtServiceBasePrivate(nm);
664664
d_ptr->q_ptr = this;
665665

666-
d_ptr->serviceFlags = 0;
666+
d_ptr->serviceFlags = static_cast<ServiceFlags>(0);
667667
d_ptr->sysd = 0;
668668
for (int i = 0; i < argc; ++i)
669669
d_ptr->args.append(QString::fromLocal8Bit(argv[i]));

qtservice/src/qtservice.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
# define QT_QTSERVICE_EXPORT
6060
#endif
6161

62-
class QStringList;
62+
//class QStringList;
6363
class QtServiceControllerPrivate;
6464

6565
class QT_QTSERVICE_EXPORT QtServiceController

qtservice/src/qtservice_win.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -737,10 +737,17 @@ class QtServiceAppEventFilter : public QAbstractNativeEventFilter
737737
{
738738
public:
739739
QtServiceAppEventFilter() {}
740-
bool nativeEventFilter(const QByteArray &eventType, void *message, long *result);
740+
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
741+
virtual bool nativeEventFilter(const QByteArray &eventType, void *message, qintptr *result);
742+
#else
743+
bool nativeEventFilter(const QByteArray &eventType, void *message, long *result) override;
744+
#endif
741745
};
742-
746+
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
747+
bool QtServiceAppEventFilter::nativeEventFilter(const QByteArray &, void *message, qintptr *result)
748+
#else
743749
bool QtServiceAppEventFilter::nativeEventFilter(const QByteArray &, void *message, long *result)
750+
#endif
744751
{
745752
MSG *winMessage = (MSG*)message;
746753
if (winMessage->message == WM_ENDSESSION && (winMessage->lParam & ENDSESSION_LOGOFF)) {

0 commit comments

Comments
 (0)