Skip to content

Commit

Permalink
QtService: support qt6
Browse files Browse the repository at this point in the history
Change-Id: I1a2aa1cb83e7cbff96ba1d4f3bd2cc7d8c0756cd
  • Loading branch information
KangLin committed Feb 16, 2022
1 parent 67af2fe commit 9c3a3ec
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
4 changes: 4 additions & 0 deletions qtservice/examples/interactive/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
****************************************************************************/

#include <QApplication>
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <QDesktopWidget>
#endif
#include <QLabel>
#include <QDir>
#include <QSettings>
Expand Down Expand Up @@ -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();
}

Expand Down
12 changes: 10 additions & 2 deletions qtservice/examples/server/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@
#include <QStringList>
#include <QDir>
#include <QSettings>

#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
#include <QRegularExpression>
#endif
#include "qtservice.h"

// HttpDaemon is the the class that implements the simple HTTP server.
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion qtservice/src/qtservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ServiceFlags>(0);
d_ptr->sysd = 0;
for (int i = 0; i < argc; ++i)
d_ptr->args.append(QString::fromLocal8Bit(argv[i]));
Expand Down
11 changes: 9 additions & 2 deletions qtservice/src/qtservice_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit 9c3a3ec

Please sign in to comment.