Skip to content

Commit 9fd2c34

Browse files
committed
QtService: support qt6
Change-Id: I1a2aa1cb83e7cbff96ba1d4f3bd2cc7d8c0756cd
1 parent 75622fc commit 9fd2c34

File tree

6 files changed

+33
-7
lines changed

6 files changed

+33
-7
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ target_wrapper.*
4646
# QtCreator CMake
4747
CMakeLists.txt.user*
4848

49-
# QtCreator 4.8< compilation database
49+
# QtCreator 4.8< compilation database
5050
compile_commands.json
5151

5252
# QtCreator local machine specific files for imported projects

qtservice/examples/interactive/main.cpp

Lines changed: 12 additions & 0 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,8 +81,12 @@ InteractiveService::~InteractiveService()
7781
void InteractiveService::start()
7882
{
7983
#if defined(Q_OS_WIN)
84+
#if QT_VERSION < QT_VERSION_CHECK(5, 4, 0)
8085
if ((QSysInfo::WindowsVersion & QSysInfo::WV_NT_based) &&
8186
(QSysInfo::WindowsVersion >= QSysInfo::WV_VISTA)) {
87+
#else
88+
if(QSysInfo::productVersion().toUInt() >= 8) {
89+
#endif
8290
logMessage( "Service GUI not allowed on Windows Vista. See the documentation for this example for more information.", QtServiceBase::Error );
8391
return;
8492
}
@@ -87,7 +95,11 @@ void InteractiveService::start()
8795
qApp->setQuitOnLastWindowClosed(false);
8896

8997
gui = new QLabel("Service", 0, Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint);
98+
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
9099
gui->move(QApplication::desktop()->availableGeometry().topLeft());
100+
#else
101+
gui->move(QGuiApplication::primaryScreen()->availableGeometry().topLeft());
102+
#endif
91103
gui->show();
92104
}
93105

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)