diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..a3775ce4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,122 @@ +# C++ objects and libs +*.slo +*.lo +*.o +*.a +*.la +*.lai +*.so +*.so.* +*.dll +*.dylib +*.json + +# Qt-es +object_script.*.Release +object_script.*.Debug +*_plugin_import.cpp +/.qmake.cache +/.qmake.stash +*.pro.user +*.pro.user.* +*.qbs.user +*.qbs.user.* +*.moc +moc_*.cpp +moc_*.h +qrc_*.cpp +ui_*.h +*.qmlc +*.jsc +Makefile* +*build-* +*.qm +*.prl + +# Qt unit tests +target_wrapper.* + +# QtCreator +*.autosave + +# QtCreator Qml +*.qmlproject.user +*.qmlproject.user.* + +# QtCreator CMake +CMakeLists.txt.user* + +# QtCreator 4.8< compilation database +compile_commands.json + +# QtCreator local machine specific files for imported projects +*creator.user* + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app + +# Platform Specifics - auto generated files +PlatformSpecifics/Windows/*.rc + +# Visual studio - project files +*.sln +*.suo +*.vcxproj +*.vcxproj.filters +*.vcxproj.user + +# Visual Studio - Build Results +[Dd]ebug/ +[Rr]elease/ +[Mm]in[Ss]ize[Rr]el/ +[Rr]el[Ww]ith[Dd]eb[Ii]nfo/ +build*/ + +# Visual Studio - Browsing Database File +*.sdf +*.opensdf + +#osx xcode +DerivedData/ +*.DS_Store +*.build +*.xcodeproj + +#CPACK related files +CPackConfig-*.cmake +_CPack_Packages/ + +#packages +*.tar.gz +*.zip + +*.swp +*.*~ + +build_doxygen diff --git a/qtservice/CMakeLists.txt b/qtservice/CMakeLists.txt new file mode 100644 index 00000000..3a81129e --- /dev/null +++ b/qtservice/CMakeLists.txt @@ -0,0 +1,138 @@ +# Author: Kang Lin + +cmake_minimum_required(VERSION 3.5) + +project(QtService) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) +#set(CMAKE_CXX_STANDARD 11) +#set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_VERBOSE_MAKEFILE ON CACHE BOOL "verbose") +if(CMAKE_VERSION VERSION_LESS "3.7.0") + set(CMAKE_INCLUDE_CURRENT_DIR ON) +endif() + +# Open qt compile tool +SET(CMAKE_AUTOUIC ON) +SET(CMAKE_AUTOMOC ON) +SET(CMAKE_AUTORCC ON) + +# Need qt compones +find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core) +find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core) +message("QT_VERSION:${Qt${QT_VERSION_MAJOR}_VERSION}") +get_filename_component(QT_INSTALL_DIR "${Qt${QT_VERSION_MAJOR}_DIR}/../../.." ABSOLUTE) +message("QT_INSTALL_DIR:${QT_INSTALL_DIR}") + +if(POLICY CMP0083) + cmake_policy(SET CMP0083 NEW) +endif() + +if(POLICY CMP0020) + cmake_policy(SET CMP0020 NEW) +endif() + +SET(BUILD_VERSION "v0.0.1") +# Find Git Version Patch +IF(EXISTS "${CMAKE_SOURCE_DIR}/.git") + if(NOT GIT) + SET(GIT $ENV{GIT}) + endif() + if(NOT GIT) + FIND_PROGRAM(GIT NAMES git git.exe git.cmd) + endif() + IF(GIT) + EXECUTE_PROCESS( + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + COMMAND ${GIT} describe --tags + OUTPUT_VARIABLE GIT_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE + ) + if(NOT GIT_VERSION) + EXECUTE_PROCESS( + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + COMMAND ${GIT} rev-parse --short HEAD + OUTPUT_VARIABLE GIT_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE + ) + endif() + SET(BUILD_VERSION ${GIT_VERSION}) + ENDIF() +ENDIF() +message("BUILD_VERSION:${BUILD_VERSION}") +set(VERSION ${BUILD_VERSION}) + +if(NOT DEFINED CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE "Release") +endif(NOT DEFINED CMAKE_BUILD_TYPE) +string(TOLOWER "${CMAKE_BUILD_TYPE}" build_type) +if("debug" STREQUAL build_type) + add_definitions(-D_DEBUG) +endif() + +IF(MSVC) + # This option is to enable the /MP switch for Visual Studio 2005 and above compilers + OPTION(WIN32_USE_MP "Set to ON to build with the /MP option (Visual Studio 2005 and above)." ON) + MARK_AS_ADVANCED(WIN32_USE_MP) + IF(WIN32_USE_MP) + #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP") + add_compile_options(/MP) + ENDIF(WIN32_USE_MP) + add_compile_options("$<$:/utf-8>") + add_compile_options("$<$:/utf-8>") +ENDIF(MSVC) + +SET(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libs") +if (BUILD_SHARED_LIBS) + add_definitions(-DBUILD_SHARED_LIBS) + if (CMAKE_COMPILER_IS_GNUCXX AND NOT MINGW) + # Just setting CMAKE_POSITION_INDEPENDENT_CODE should be enough to set + # -fPIC for GCC but sometimes it still doesn't get set, so make sure it + # does. + add_definitions("-fPIC") + endif() + set(CMAKE_POSITION_INDEPENDENT_CODE ON) +else(BUILD_SHARED_LIBS) + add_definitions(-DQT_STATICPLUGIN) +endif(BUILD_SHARED_LIBS) + +include(CMakePackageConfigHelpers) +include(GNUInstallDirs) +include(GenerateExportHeader) +include(CheckIncludeFile) +include(CheckIncludeFileCXX) +include(CheckFunctionExists) + +#CHECK_INCLUDE_FILE_CXX("string" HAVE_STRING_H) +#check_include_file("math.h" HAVE_MATH_H) + +#check_function_exists("fabs" HAVE_FABS) + +set(BUILD_PLATFORM "${CMAKE_SYSTEM_NAME}") +# ---------------------------------------------------------------------------- +# Detect compiler and target platform architecture +# ---------------------------------------------------------------------------- +if(NOT ANDROID) + if(X86_64 OR CMAKE_SIZEOF_VOID_P EQUAL 8) + set(BUILD_ARCH x86_64) + elseif(X86 OR CMAKE_SIZEOF_VOID_P EQUAL 4) + set(BUILD_ARCH x86) + endif() +else() + set(BUILD_ARCH ${CMAKE_SYSTEM_PROCESSOR}) +endif() + +add_subdirectory(src) + +option(BUILD_EXAMPLES "Build examples" OFF) +if(BUILD_EXAMPLES) + add_subdirectory(examples) +endif(BUILD_EXAMPLES) + +# Create will be delete files +CONFIGURE_FILE( + "${CMAKE_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in" + "${CMAKE_BINARY_DIR}/cmake_uninstall.cmake" + IMMEDIATE @ONLY) +# Create unistall target +ADD_CUSTOM_TARGET(uninstall + "${CMAKE_COMMAND}" -P "${CMAKE_BINARY_DIR}/cmake_uninstall.cmake" + ) diff --git a/qtservice/cmake/QtService.pc.in b/qtservice/cmake/QtService.pc.in new file mode 100644 index 00000000..1a665472 --- /dev/null +++ b/qtservice/cmake/QtService.pc.in @@ -0,0 +1,12 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=@CMAKE_INSTALL_PREFIX@ +libdir=@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@ +includedir=@CMAKE_INSTALL_PREFIX@/include + +Name: @PROJECT_NAME@ +Description: +Version: @BUILD_VERSION@ +Requires: +Requires.private: +Libs: -L${libdir} -l@PROJECT_NAME@ +Cflags: -I${includedir} diff --git a/qtservice/cmake/QtServiceConfig.cmake.in b/qtservice/cmake/QtServiceConfig.cmake.in new file mode 100644 index 00000000..949471fa --- /dev/null +++ b/qtservice/cmake/QtServiceConfig.cmake.in @@ -0,0 +1,13 @@ +@PACKAGE_INIT@ + +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/") + +include(CMakeFindDependencyMacro) +#foreach(dependens_lib @QTSERVICE_DEPENDENS@) +# find_dependency(${dependens_lib}) +#endforeach() + +find_dependency(Qt@QT_VERSION_MAJOR@ COMPONENTS @QT_COMPONENTS@) + +include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") + diff --git a/qtservice/cmake/cmake_uninstall.cmake.in b/qtservice/cmake/cmake_uninstall.cmake.in new file mode 100644 index 00000000..d59ef98f --- /dev/null +++ b/qtservice/cmake/cmake_uninstall.cmake.in @@ -0,0 +1,57 @@ +# Author: Kang Lin(kl222@126.com) + +# Use: Please add the follow code to CMakeLists.txt + +# # Install runtime target +# add_custom_target(install-runtime +# COMMAND +# "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=Runtime +# -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_install.cmake" +# ) +# # Uninstall runtime target +# add_custom_target(uninstall-runtime +# COMMAND +# "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=Runtime +# -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" +# ) +# # Create will be delete files +# CONFIGURE_FILE( +# "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in" +# "${CMAKE_BINARY_DIR}/cmake_uninstall.cmake" +# IMMEDIATE @ONLY) +# # Create unistall target +# ADD_CUSTOM_TARGET(uninstall +# "${CMAKE_COMMAND}" -P "${CMAKE_BINARY_DIR}/cmake_uninstall.cmake" +# DEPENDS uninstall-runtime) + + +if(CMAKE_INSTALL_COMPONENT) + set(CMAKE_INSTALL_MANIFEST "install_manifest_${CMAKE_INSTALL_COMPONENT}.txt") +else() + set(CMAKE_INSTALL_MANIFEST "install_manifest.txt") +endif() + +IF(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/${CMAKE_INSTALL_MANIFEST}") + MESSAGE(WARNING "Cannot find install manifest: \"@CMAKE_CURRENT_BINARY_DIR@/${CMAKE_INSTALL_MANIFEST}\"") +ELSE() + + FILE(READ "@CMAKE_CURRENT_BINARY_DIR@/${CMAKE_INSTALL_MANIFEST}" files) + STRING(REGEX REPLACE "\n" ";" files "${files}") + FOREACH(file ${files}) + MESSAGE(STATUS "Uninstalling \"${file}\"") + IF(EXISTS "${file}") + EXEC_PROGRAM( + "@CMAKE_COMMAND@" ARGS "-E remove \"${file}\"" + OUTPUT_VARIABLE rm_out + RETURN_VALUE rm_retval + ) + IF("${rm_retval}" STREQUAL 0) + ELSE("${rm_retval}" STREQUAL 0) + MESSAGE(FATAL_ERROR "Problem when removing \"${file}\"") + ENDIF("${rm_retval}" STREQUAL 0) + ELSE(EXISTS "${file}") + MESSAGE(STATUS "File \"${file}\" does not exist.") + ENDIF(EXISTS "${file}") + ENDFOREACH(file) + +ENDIF() diff --git a/qtservice/examples/CMakeLists.txt b/qtservice/examples/CMakeLists.txt new file mode 100644 index 00000000..aaa1c00a --- /dev/null +++ b/qtservice/examples/CMakeLists.txt @@ -0,0 +1,3 @@ +add_subdirectory(server) +add_subdirectory(controller) +add_subdirectory(interactive) diff --git a/qtservice/examples/controller/CMakeLists.txt b/qtservice/examples/controller/CMakeLists.txt new file mode 100644 index 00000000..f7cf3ec3 --- /dev/null +++ b/qtservice/examples/controller/CMakeLists.txt @@ -0,0 +1,6 @@ +# Author: Kang Lin + +project(controller) + +add_executable(${PROJECT_NAME} main.cpp) +target_link_libraries(${PROJECT_NAME} PRIVATE QtService) diff --git a/qtservice/examples/interactive/CMakeLists.txt b/qtservice/examples/interactive/CMakeLists.txt new file mode 100644 index 00000000..feff7739 --- /dev/null +++ b/qtservice/examples/interactive/CMakeLists.txt @@ -0,0 +1,16 @@ +# Author: Kang Lin + +project(interactive) + +SET(QT_COMPONENTS Gui Widgets) +find_package(QT NAMES Qt6 Qt5 COMPONENTS Core) +find_package(Qt${QT_VERSION_MAJOR} COMPONENTS ${QT_COMPONENTS}) +if(Qt${QT_VERSION_MAJOR}_FOUND) + FOREACH(_COMPONENT ${QT_COMPONENTS}) + LIST(APPEND QT_LIBRARIES Qt${QT_VERSION_MAJOR}::${_COMPONENT}) + ENDFOREACH() +endif() +message("${PROJECT_NAME} QT_LIBRARIES:${QT_LIBRARIES}") + +add_executable(${PROJECT_NAME} main.cpp) +target_link_libraries(${PROJECT_NAME} PRIVATE QtService ${QT_LIBRARIES}) diff --git a/qtservice/examples/interactive/main.cpp b/qtservice/examples/interactive/main.cpp index d4858b19..92abf6bf 100644 --- a/qtservice/examples/interactive/main.cpp +++ b/qtservice/examples/interactive/main.cpp @@ -39,7 +39,11 @@ ****************************************************************************/ #include +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) #include +#else +#include +#endif #include #include #include @@ -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(); } diff --git a/qtservice/examples/server/CMakeLists.txt b/qtservice/examples/server/CMakeLists.txt new file mode 100644 index 00000000..731fadf8 --- /dev/null +++ b/qtservice/examples/server/CMakeLists.txt @@ -0,0 +1,17 @@ +# Author: Kang Lin + +project(httpservice) + +# Need qt components +set(QT_COMPONENTS Network) +find_package(Qt${QT_VERSION_MAJOR} COMPONENTS ${QT_COMPONENTS}) +if(Qt${QT_VERSION_MAJOR}_FOUND) + FOREACH(_COMPONENT ${QT_COMPONENTS}) + LIST(APPEND QT_LIBRARIES Qt${QT_VERSION_MAJOR}::${_COMPONENT}) + ENDFOREACH() +endif() +message("${PROJECT_NAME} QT_LIBRARIES:${QT_LIBRARIES}") + +add_executable(${PROJECT_NAME} main.cpp) + +target_link_libraries(${PROJECT_NAME} PRIVATE QtService ${QT_LIBRARIES}) diff --git a/qtservice/examples/server/main.cpp b/qtservice/examples/server/main.cpp index ebcc218e..009579e4 100644 --- a/qtservice/examples/server/main.cpp +++ b/qtservice/examples/server/main.cpp @@ -46,7 +46,9 @@ #include #include #include - +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +#include +#endif #include "qtservice.h" // HttpDaemon is the the class that implements the simple HTTP server. @@ -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); diff --git a/qtservice/src/CMakeLists.txt b/qtservice/src/CMakeLists.txt new file mode 100644 index 00000000..3a17e832 --- /dev/null +++ b/qtservice/src/CMakeLists.txt @@ -0,0 +1,124 @@ +# Author: Kang Lin + +cmake_minimum_required(VERSION 3.5) + +if(CMAKE_VERSION VERSION_LESS "3.16.0") + set(CMAKE_INCLUDE_CURRENT_DIR ON) +endif() + +project(QtService) + +# Open qt complie tools +SET(CMAKE_AUTOUIC ON) +SET(CMAKE_AUTOMOC ON) +SET(CMAKE_AUTORCC ON) +SET(CMAKE_VERBOSE_MAKEFILE ON) + +set(QT_COMPONENTS Core) +# Need qt components +if(UNIX) + list(APPEND QT_COMPONENTS Network) +endif() +find_package(QT NAMES Qt6 Qt5 COMPONENTS Core) +find_package(Qt${QT_VERSION_MAJOR} COMPONENTS ${QT_COMPONENTS}) +if(Qt${QT_VERSION_MAJOR}_FOUND) + FOREACH(_COMPONENT ${QT_COMPONENTS}) + LIST(APPEND QT_LIBRARIES Qt${QT_VERSION_MAJOR}::${_COMPONENT}) + ENDFOREACH() +endif() +message("${PROJECT_NAME} QT_LIBRARIES:${QT_LIBRARIES}") + +set(SOURCE_FILES + qtservice.cpp + ) + +set(INSTALL_HEADER_FILES + QtService + QtServiceBase + QtServiceController + qtservice.h + ) + +set(HEADER_FILES ${INSTALL_HEADER_FILES} + qtservice_p.h + ) + +if(UNIX) + list(APPEND SOURCE_FILES + qtservice_unix.cpp + qtunixsocket.cpp + qtunixserversocket.cpp) + list(APPEND HEADER_FILES + qtunixserversocket.h + qtunixsocket.h) +endif() +if(WIN32) + list(APPEND SOURCE_FILES + qtservice_win.cpp) +endif() + +add_library(${PROJECT_NAME} ${SOURCE_FILES} ${HEADER_FILES}) +set_target_properties(${PROJECT_NAME} PROPERTIES + PUBLIC_HEADER "${INSTALL_HEADER_FILES}" # Install head files + ) +target_link_libraries(${PROJECT_NAME} PUBLIC ${QT_LIBRARIES}) +target_include_directories(${PROJECT_NAME} + PUBLIC $ + $) + +if(WIN32) + if(BUILD_SHARED_LIBS) + target_compile_definitions(${PROJECT_NAME} PRIVATE QT_QTSERVICE_EXPORT UNICODE) + endif() + INSTALL(TARGETS ${PROJECT_NAME} + EXPORT ${PROJECT_NAME}Targets + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" + LIBRARY DESTINATION "${CMAKE_INSTALL_BINDIR}" + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME} + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + ) +else() + INSTALL(TARGETS ${PROJECT_NAME} + EXPORT ${PROJECT_NAME}Targets + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME} + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + ) +endif() +# Install cmake configure files +install(EXPORT ${PROJECT_NAME}Targets + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" + ) + +export(TARGETS ${PROJECT_NAME} + APPEND FILE ${CMAKE_BINARY_DIR}/${PROJECT_NAME}Config.cmake + ) + +include(CMakePackageConfigHelpers) +configure_package_config_file( + ${CMAKE_CURRENT_SOURCE_DIR}/../cmake/QtServiceConfig.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/QtServiceConfig.cmake + INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" + ) + +# Install cmake version configure file +write_basic_package_version_file( + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" + VERSION ${BUILD_VERSION} + COMPATIBILITY AnyNewerVersion) + +install(FILES + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/QtServiceConfig.cmake" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") + +configure_file(${CMAKE_SOURCE_DIR}/cmake/QtService.pc.in + ${CMAKE_BINARY_DIR}/QtService.pc + @ONLY) +install(FILES + ${CMAKE_BINARY_DIR}/QtService.pc + DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig + ) diff --git a/qtservice/src/qtservice.cpp b/qtservice/src/qtservice.cpp index 5eae058e..3374a1e6 100644 --- a/qtservice/src/qtservice.cpp +++ b/qtservice/src/qtservice.cpp @@ -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(0); d_ptr->sysd = 0; for (int i = 0; i < argc; ++i) d_ptr->args.append(QString::fromLocal8Bit(argv[i])); diff --git a/qtservice/src/qtservice.h b/qtservice/src/qtservice.h index 01d5b07f..4fb3c3c4 100644 --- a/qtservice/src/qtservice.h +++ b/qtservice/src/qtservice.h @@ -59,7 +59,7 @@ # define QT_QTSERVICE_EXPORT #endif -class QStringList; +//class QStringList; class QtServiceControllerPrivate; class QT_QTSERVICE_EXPORT QtServiceController diff --git a/qtservice/src/qtservice_win.cpp b/qtservice/src/qtservice_win.cpp index e5b7ecc5..3b9a1ae1 100644 --- a/qtservice/src/qtservice_win.cpp +++ b/qtservice/src/qtservice_win.cpp @@ -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)) {