diff options
author | Friedemann Kleint <Friedemann.Kleint@digia.com> | 2013-01-07 12:53:57 +0100 |
---|---|---|
committer | Joerg Bornemann <joerg.bornemann@digia.com> | 2013-01-11 16:26:22 +0100 |
commit | 4f22802c0d507985f3862942d70dea0f4ead97d1 (patch) | |
tree | 5faf87875192dcddf72df8ec3fca092a8baac7ef | |
parent | 67a72e3bc2e49ffc9e99b9845b1c314bf86f6941 (diff) |
Fix compilation of the Qt Service Solution with Qt 5.
Change-Id: I92e93bec3d39c135c00424eca64c2bc65582d49e
Reviewed-by: Jonathan Liu <net147@gmail.com>
Reviewed-by: Andy Shaw <andy.shaw@digia.com>
Reviewed-by: Joerg Bornemann <joerg.bornemann@digia.com>
-rw-r--r-- | qtservice/examples/interactive/interactive.pro | 1 | ||||
-rw-r--r-- | qtservice/examples/server/main.cpp | 6 | ||||
-rw-r--r-- | qtservice/src/qtservice_win.cpp | 38 |
3 files changed, 45 insertions, 0 deletions
diff --git a/qtservice/examples/interactive/interactive.pro b/qtservice/examples/interactive/interactive.pro index 6dba6f8..9bf13a5 100644 --- a/qtservice/examples/interactive/interactive.pro +++ b/qtservice/examples/interactive/interactive.pro @@ -1,5 +1,6 @@ TEMPLATE = app CONFIG += console qt +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets SOURCES = main.cpp diff --git a/qtservice/examples/server/main.cpp b/qtservice/examples/server/main.cpp index 50f9e83..ebcc218 100644 --- a/qtservice/examples/server/main.cpp +++ b/qtservice/examples/server/main.cpp @@ -145,8 +145,14 @@ protected: { QCoreApplication *app = application(); +#if QT_VERSION < 0x040100 quint16 port = (app->argc() > 1) ? QString::fromLocal8Bit(app->argv()[1]).toUShort() : 8080; +#else + const QStringList arguments = QCoreApplication::arguments(); + quint16 port = (arguments.size() > 1) ? + arguments.at(1).toUShort() : 8080; +#endif daemon = new HttpDaemon(port, app); if (!daemon->isListening()) { diff --git a/qtservice/src/qtservice_win.cpp b/qtservice/src/qtservice_win.cpp index 6d65ff0..f4b8cc9 100644 --- a/qtservice/src/qtservice_win.cpp +++ b/qtservice/src/qtservice_win.cpp @@ -54,6 +54,9 @@ #include <QAbstractEventDispatcher> #include <QVector> #include <QThread> +#if QT_VERSION >= 0x050000 +# include <QAbstractNativeEventFilter> +#endif #include <stdio.h> #if defined(QTSERVICE_DEBUG) #include <QDebug> @@ -487,7 +490,9 @@ public: QStringList serviceArgs; static QtServiceSysPrivate *instance; +#if QT_VERSION < 0x050000 static QCoreApplication::EventFilter nextFilter; +#endif QWaitCondition condition; QMutex mutex; @@ -512,7 +517,9 @@ void QtServiceControllerHandler::customEvent(QEvent *e) QtServiceSysPrivate *QtServiceSysPrivate::instance = 0; +#if QT_VERSION < 0x050000 QCoreApplication::EventFilter QtServiceSysPrivate::nextFilter = 0; +#endif QtServiceSysPrivate::QtServiceSysPrivate() { @@ -716,6 +723,30 @@ protected: /* Ignore WM_ENDSESSION system events, since they make the Qt kernel quit */ + +#if QT_VERSION >= 0x050000 + +class QtServiceAppEventFilter : public QAbstractNativeEventFilter +{ +public: + QtServiceAppEventFilter() {} + bool nativeEventFilter(const QByteArray &eventType, void *message, long *result); +}; + +bool QtServiceAppEventFilter::nativeEventFilter(const QByteArray &, void *message, long *result) +{ + MSG *winMessage = (MSG*)message; + if (winMessage->message == WM_ENDSESSION && (winMessage->lParam & ENDSESSION_LOGOFF)) { + *result = TRUE; + return true; + } + return false; +} + +Q_GLOBAL_STATIC(QtServiceAppEventFilter, qtServiceAppEventFilter) + +#else + bool myEventFilter(void* message, long* result) { MSG* msg = reinterpret_cast<MSG*>(message); @@ -729,6 +760,8 @@ bool myEventFilter(void* message, long* result) return true; } +#endif + /* There are three ways we can be started: - By a service controller (e.g. the Services control panel), with @@ -787,7 +820,12 @@ bool QtServiceBasePrivate::start() QCoreApplication *app = QCoreApplication::instance(); if (!app) return false; + +#if QT_VERSION >= 0x050000 + QAbstractEventDispatcher::instance()->installNativeEventFilter(qtServiceAppEventFilter()); +#else QtServiceSysPrivate::nextFilter = app->setEventFilter(myEventFilter); +#endif sys->controllerHandler = new QtServiceControllerHandler(sys); |