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 18, 2022
1 parent 917a3f1 commit b93d665
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 11 deletions.
23 changes: 18 additions & 5 deletions qtservice/examples/interactive/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@
****************************************************************************/

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

Expand Down
11 changes: 9 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,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);
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
2 changes: 1 addition & 1 deletion qtservice/src/qtservice.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
# define QT_QTSERVICE_EXPORT
#endif

class QStringList;
//class QStringList;
class QtServiceControllerPrivate;

class QT_QTSERVICE_EXPORT QtServiceController
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 b93d665

Please sign in to comment.