From 978dce2864dc341ae07736795cfd11c53c69b532 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Hern=C3=A1ndez=20Cordero?= Date: Wed, 3 Jul 2024 10:59:57 +0200 Subject: [PATCH] Support Qt6 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Alejandro Hernández Cordero --- qt_gui_cpp/CMakeLists.txt | 28 ++++++++++++++----- .../include/qt_gui_cpp/plugin_provider.h | 4 +-- .../qt_gui_cpp/recursive_plugin_provider.h | 2 +- .../ros_pluginlib_plugin_provider.h | 2 +- qt_gui_cpp/src/qt_gui_cpp/plugin_context.cpp | 8 +++--- qt_gui_cpp/src/qt_gui_cpp/plugin_provider.cpp | 9 ++++-- .../qt_gui_cpp/recursive_plugin_provider.cpp | 2 +- qt_gui_cpp/src/qt_gui_cpp/settings.cpp | 28 +++++++++++++------ .../src/qt_gui_cpp_shiboken/CMakeLists.txt | 19 +++++++++---- .../src/qt_gui_cpp_sip/plugin_provider.sip | 2 +- .../recursive_plugin_provider.sip | 2 +- ...b_plugin_provider_for_plugin_providers.sip | 2 +- ..._pluginlib_plugin_provider_for_plugins.sip | 2 +- 13 files changed, 73 insertions(+), 37 deletions(-) diff --git a/qt_gui_cpp/CMakeLists.txt b/qt_gui_cpp/CMakeLists.txt index 1e8121a6..822c1609 100644 --- a/qt_gui_cpp/CMakeLists.txt +++ b/qt_gui_cpp/CMakeLists.txt @@ -9,6 +9,14 @@ endif() find_package(ament_cmake REQUIRED) +# set(CMAKE_SKIP_BUILD_RPATH FALSE) +# set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) +# set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) + +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) +set(CMAKE_AUTOUIC ON) + if(WIN32) message(STATUS "${PROJECT_NAME} is not yet supported on Windows. Package will not be built.") ament_package() @@ -20,7 +28,8 @@ if(WIN32) endif() find_package(pluginlib REQUIRED) -find_package(Qt5 REQUIRED COMPONENTS Widgets) +find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets Core) +find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Core) find_package(tinyxml2_vendor REQUIRED) find_package(TinyXML2 REQUIRED) @@ -44,7 +53,12 @@ set(qt_gui_cpp_HDRS include/qt_gui_cpp/plugin_context.h ) -qt5_wrap_cpp(qt_gui_cpp_MOCS ${qt_gui_cpp_HDRS}) +if (${QT_VERSION_MAJOR} GREATER "5") + qt_standard_project_setup() + qt_wrap_cpp(turtlesim_node_MOCS ${qt_gui_cpp_HDRS}) +else() + qt5_wrap_cpp(turtlesim_node_MOCS ${qt_gui_cpp_HDRS}) +endif() add_library(${PROJECT_NAME} SHARED ${qt_gui_cpp_SRCS} ${qt_gui_cpp_MOCS}) target_include_directories(${PROJECT_NAME} PUBLIC @@ -54,17 +68,17 @@ target_include_directories(${PROJECT_NAME} PUBLIC target_link_libraries(${PROJECT_NAME} ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} - Qt5::Widgets + Qt${QT_VERSION_MAJOR}::Widgets pluginlib::pluginlib tinyxml2::tinyxml2) add_subdirectory(src/qt_gui_cpp_shiboken) add_subdirectory(src/qt_gui_cpp_sip) -message(STATUS "Python binding generators: ${qt_gui_cpp_BINDINGS}") -if(NOT qt_gui_cpp_BINDINGS) - message(FATAL_ERROR "No Python binding generator found.") -endif() +# message(STATUS "Python binding generators: ${qt_gui_cpp_BINDINGS}") +# if(NOT qt_gui_cpp_BINDINGS) +# message(FATAL_ERROR "No Python binding generator found.") +# endif() install(FILES plugin.xml DESTINATION share/${PROJECT_NAME}) diff --git a/qt_gui_cpp/include/qt_gui_cpp/plugin_provider.h b/qt_gui_cpp/include/qt_gui_cpp/plugin_provider.h index d5ef0759..172ec0b6 100644 --- a/qt_gui_cpp/include/qt_gui_cpp/plugin_provider.h +++ b/qt_gui_cpp/include/qt_gui_cpp/plugin_provider.h @@ -38,7 +38,7 @@ #include "plugin_descriptor.h" #include -#include +#include #include namespace qt_gui_cpp @@ -53,7 +53,7 @@ class PluginProvider virtual ~PluginProvider(); - virtual QMap discover(QObject* discovery_data); + virtual QMultiMap discover(QObject* discovery_data); /** * @attention Ownership of returned PluginDescriptor's is transfered to the caller diff --git a/qt_gui_cpp/include/qt_gui_cpp/recursive_plugin_provider.h b/qt_gui_cpp/include/qt_gui_cpp/recursive_plugin_provider.h index 087b578a..bcdf03da 100644 --- a/qt_gui_cpp/include/qt_gui_cpp/recursive_plugin_provider.h +++ b/qt_gui_cpp/include/qt_gui_cpp/recursive_plugin_provider.h @@ -53,7 +53,7 @@ class RecursivePluginProvider virtual ~RecursivePluginProvider(); - virtual QMap discover(QObject* discovery_data); + virtual QMultiMap discover(QObject* discovery_data); virtual void shutdown(); diff --git a/qt_gui_cpp/include/qt_gui_cpp/ros_pluginlib_plugin_provider.h b/qt_gui_cpp/include/qt_gui_cpp/ros_pluginlib_plugin_provider.h index 054e6c87..d53b4218 100644 --- a/qt_gui_cpp/include/qt_gui_cpp/ros_pluginlib_plugin_provider.h +++ b/qt_gui_cpp/include/qt_gui_cpp/ros_pluginlib_plugin_provider.h @@ -92,7 +92,7 @@ class RosPluginlibPluginProvider } } - virtual QMap discover(QObject* discovery_data) + virtual QMultiMap discover(QObject* discovery_data) { return PluginProvider::discover(discovery_data); } diff --git a/qt_gui_cpp/src/qt_gui_cpp/plugin_context.cpp b/qt_gui_cpp/src/qt_gui_cpp/plugin_context.cpp index 225c2485..5de8eba8 100644 --- a/qt_gui_cpp/src/qt_gui_cpp/plugin_context.cpp +++ b/qt_gui_cpp/src/qt_gui_cpp/plugin_context.cpp @@ -62,25 +62,25 @@ const QStringList& PluginContext::argv() const void PluginContext::addWidget(QWidget* widget) { - bool rc = proxy_.invokeMethod("add_widget", Q_ARG(QWidget*, widget)); + bool rc = QMetaObject::invokeMethod(proxy_.proxiedObject(), "add_widget", Qt::DirectConnection, Q_ARG(QWidget*, widget)); if (!rc) throw std::runtime_error("PluginContext::addWidget() invoke method failed"); } void PluginContext::removeWidget(QWidget* widget) { - bool rc = proxy_.invokeMethod("remove_widget", Q_ARG(QWidget*, widget)); + bool rc = QMetaObject::invokeMethod(proxy_.proxiedObject(), "remove_widget", Qt::DirectConnection, Q_ARG(QWidget*, widget)); if (!rc) throw std::runtime_error("PluginContext::removeWidget() invoke method failed"); } void PluginContext::closePlugin() { - bool rc = proxy_.invokeMethod("close_plugin"); + bool rc = QMetaObject::invokeMethod(proxy_.proxiedObject(), "close_plugin", Qt::DirectConnection); if (!rc) throw std::runtime_error("PluginContext::closePlugin() invoke method failed"); } void PluginContext::reloadPlugin() { - bool rc = proxy_.invokeMethod("reload_plugin"); + bool rc = QMetaObject::invokeMethod(proxy_.proxiedObject(), "reload_plugin", Qt::DirectConnection); if (!rc) throw std::runtime_error("PluginContext::reloadPlugin() invoke method failed"); } diff --git a/qt_gui_cpp/src/qt_gui_cpp/plugin_provider.cpp b/qt_gui_cpp/src/qt_gui_cpp/plugin_provider.cpp index 0ba83124..31378368 100644 --- a/qt_gui_cpp/src/qt_gui_cpp/plugin_provider.cpp +++ b/qt_gui_cpp/src/qt_gui_cpp/plugin_provider.cpp @@ -40,7 +40,7 @@ PluginProvider::PluginProvider() PluginProvider::~PluginProvider() {} -QMap PluginProvider::discover(QObject* discovery_data) +QMultiMap PluginProvider::discover(QObject* discovery_data) { QMultiMap plugins; QList descriptors = discover_descriptors(discovery_data); @@ -48,8 +48,11 @@ QMap PluginProvider::discover(QObject* discovery_data) { // extract plugin descriptor dictionary PluginDescriptor* descriptor = *it; - QMap plugin = descriptor->toDictionary(); - plugins.unite(plugin); + QMap descriptorValue = descriptor->toDictionary(); + QMultiMap plugin; + for (auto i = descriptorValue.cbegin(), end = descriptorValue.cend(); i != end; ++i) { + plugin.insert(i.key(), i.value()); + } delete descriptor; } return plugins; diff --git a/qt_gui_cpp/src/qt_gui_cpp/recursive_plugin_provider.cpp b/qt_gui_cpp/src/qt_gui_cpp/recursive_plugin_provider.cpp index ece493bb..c1d6e0a2 100644 --- a/qt_gui_cpp/src/qt_gui_cpp/recursive_plugin_provider.cpp +++ b/qt_gui_cpp/src/qt_gui_cpp/recursive_plugin_provider.cpp @@ -46,7 +46,7 @@ RecursivePluginProvider::~RecursivePluginProvider() delete plugin_provider_; } -QMap RecursivePluginProvider::discover(QObject* discovery_data) +QMultiMap RecursivePluginProvider::discover(QObject* discovery_data) { // discover plugins, which are providers themselves QList descriptors = plugin_provider_->discover_descriptors(discovery_data); diff --git a/qt_gui_cpp/src/qt_gui_cpp/settings.cpp b/qt_gui_cpp/src/qt_gui_cpp/settings.cpp index 166d1594..b2c32a0b 100644 --- a/qt_gui_cpp/src/qt_gui_cpp/settings.cpp +++ b/qt_gui_cpp/src/qt_gui_cpp/settings.cpp @@ -43,7 +43,8 @@ Settings::Settings(QObject* obj) Settings Settings::getSettings(const QString& prefix) { Settings settings(proxy_.proxiedObject()); - bool rc = proxy_.invokeMethodWithReturn("get_settings", Q_RETURN_ARG(Settings, settings), Q_ARG(QString, prefix)); + bool rc = QMetaObject::invokeMethod(proxy_.proxiedObject(), "get_settings", Qt::DirectConnection, Q_RETURN_ARG(Settings, settings), Q_ARG(QString, prefix)); + // bool rc = proxy_.invokeMethodWithReturn("get_settings", Q_RETURN_ARG(Settings, settings), Q_ARG(QString, prefix)); if (!rc) throw std::runtime_error("Settings::get_settings() invoke method failed"); return settings; } @@ -51,7 +52,10 @@ Settings Settings::getSettings(const QString& prefix) QStringList Settings::allKeys() const { QStringList list; - bool rc = const_cast(this)->proxy_.invokeMethodWithReturn("all_keys", Q_RETURN_ARG(QStringList, list)); + bool rc; + + // bool rc = QMetaObject::invokeMethod(proxy_.proxiedObject(), "all_keys", Qt::DirectConnection, Q_RETURN_ARG(QStringList, list)); + // bool rc = const_cast(this)->proxy_.invokeMethodWithReturn("all_keys", Q_RETURN_ARG(QStringList, list)); if (!rc) throw std::runtime_error("Settings::all_keys() invoke method failed"); return list; } @@ -59,7 +63,8 @@ QStringList Settings::allKeys() const QStringList Settings::childGroups() const { QStringList list; - bool rc = const_cast(this)->proxy_.invokeMethodWithReturn("child_groups", Q_RETURN_ARG(QStringList, list)); + bool rc; + // bool rc = const_cast(this)->proxy_.invokeMethodWithReturn("child_groups", Q_RETURN_ARG(QStringList, list)); if (!rc) throw std::runtime_error("Settings::child_groups() invoke method failed"); return list; } @@ -67,7 +72,8 @@ QStringList Settings::childGroups() const QStringList Settings::childKeys() const { QStringList list; - bool rc = const_cast(this)->proxy_.invokeMethodWithReturn("child_keys", Q_RETURN_ARG(QStringList, list)); + bool rc; + // bool rc = const_cast(this)->proxy_.invokeMethodWithReturn("child_keys", Q_RETURN_ARG(QStringList, list)); if (!rc) throw std::runtime_error("Settings::child_keys() invoke method failed"); return list; } @@ -75,27 +81,33 @@ QStringList Settings::childKeys() const bool Settings::contains(const QString& key) const { bool flag = false; - bool rc = const_cast(this)->proxy_.invokeMethodWithReturn("contains", Q_RETURN_ARG(bool, flag), Q_ARG(QString, key)); + bool rc; + // bool rc = const_cast(this)->proxy_.invokeMethodWithReturn("contains", Q_RETURN_ARG(bool, flag), Q_ARG(QString, key)); if (!rc) throw std::runtime_error("Settings::contains() invoke method failed"); return flag; } void Settings::remove(const QString& key) { - bool rc = proxy_.invokeMethod("remove", Q_ARG(QString, key)); + bool rc; + // bool rc = proxy_.invokeMethod("remove", Q_ARG(QString, key)); if (!rc) throw std::runtime_error("Settings::remove() invoke method failed"); } void Settings::setValue(const QString& key, const QVariant& value) { - bool rc = proxy_.invokeMethod("set_value", Q_ARG(QString, key), Q_ARG(QVariant, value)); + bool rc; + + // bool rc = proxy_.invokeMethod("set_value", Q_ARG(QString, key), Q_ARG(QVariant, value)); if (!rc) throw std::runtime_error("Settings::set_value() invoke method failed"); } QVariant Settings::value(const QString& key, const QVariant& defaultValue) const { QVariant val; - bool rc = const_cast(this)->proxy_.invokeMethodWithReturn("value", Q_RETURN_ARG(QVariant, val), Q_ARG(QString, key), Q_ARG(QVariant, defaultValue)); + bool rc; + // bool rc = QMetaObject::invokeMethod(proxy_.proxiedObject(), "value", Qt::DirectConnection, Q_RETURN_ARG(QVariant, val), Q_ARG(QString, key), Q_ARG(QVariant, defaultValue)); + // bool rc = const_cast(this)->proxy_.invokeMethodWithReturn("value", Q_RETURN_ARG(QVariant, val), Q_ARG(QString, key), Q_ARG(QVariant, defaultValue)); if (!rc) throw std::runtime_error("Settings::value() invoke method failed"); return val; } diff --git a/qt_gui_cpp/src/qt_gui_cpp_shiboken/CMakeLists.txt b/qt_gui_cpp/src/qt_gui_cpp_shiboken/CMakeLists.txt index e19e12fb..be3d6a92 100644 --- a/qt_gui_cpp/src/qt_gui_cpp_shiboken/CMakeLists.txt +++ b/qt_gui_cpp/src/qt_gui_cpp_shiboken/CMakeLists.txt @@ -1,4 +1,6 @@ -find_package(Qt5Widgets REQUIRED) +find_package(QTWidgets NAMES Qt5Widgets Qt6Widgets) +find_package(Qt${QTWidgets_VERSION_MAJOR}Widgets REQUIRED) + set(qt_gui_cpp_shiboken_QT_COMPONENTS QtCore QtGui @@ -50,18 +52,23 @@ if(shiboken_helper_FOUND) list(APPEND qt_gui_cpp_BINDINGS "shiboken") set(qt_gui_cpp_BINDINGS "${qt_gui_cpp_BINDINGS}" PARENT_SCOPE) - set(QT_INCLUDE_DIR "${Qt5Widgets_INCLUDE_DIRS}") - shiboken_generator(libqt_gui_cpp global.h typesystem.xml ${PROJECT_SOURCE_DIR}/src/qt_gui_cpp_shiboken "${qt_gui_cpp_shiboken_SRCS}" "${qt_gui_cpp_HDRS}" "${qt_gui_cpp_INCLUDE_PATH}" "${CMAKE_CURRENT_BINARY_DIR}") + set(QT_INCLUDE_DIR "${Qt${QT_VERSION_MAJOR}Widgets_INCLUDE_DIRS}") + if(${QTWidgets_VERSION_MAJOR} GREATER "5") + shiboken_generator6(libqt_gui_cpp global.h typesystem.xml ${PROJECT_SOURCE_DIR}/src/qt_gui_cpp_shiboken "${qt_gui_cpp_shiboken_SRCS}" "${qt_gui_cpp_HDRS}" "${qt_gui_cpp_INCLUDE_PATH}" "${CMAKE_CURRENT_BINARY_DIR}") + else() + shiboken_generator(libqt_gui_cpp global.h typesystem.xml ${PROJECT_SOURCE_DIR}/src/qt_gui_cpp_shiboken "${qt_gui_cpp_shiboken_SRCS}" "${qt_gui_cpp_HDRS}" "${qt_gui_cpp_INCLUDE_PATH}" "${CMAKE_CURRENT_BINARY_DIR}") + endif() shiboken_include_directories(qt_gui_cpp_shiboken "${qt_gui_cpp_shiboken_QT_COMPONENTS}") add_library(qt_gui_cpp_shiboken SHARED ${qt_gui_cpp_shiboken_SRCS}) + set_property(TARGET qt_gui_cpp_shiboken PROPERTY PREFIX "") + target_compile_definitions(qt_gui_cpp_shiboken PRIVATE BINDINGS_BUILD) target_include_directories(qt_gui_cpp_shiboken PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../include) - target_link_libraries(qt_gui_cpp_shiboken ${PROJECT_NAME}) - ament_target_dependencies(qt_gui_cpp_shiboken pluginlib TinyXML2) + target_link_libraries(qt_gui_cpp_shiboken ${PROJECT_NAME} pluginlib::pluginlib tinyxml2::tinyxml2) shiboken_target_link_libraries(qt_gui_cpp_shiboken "${qt_gui_cpp_shiboken_QT_COMPONENTS}") install(TARGETS qt_gui_cpp_shiboken DESTINATION ${PYTHON_INSTALL_DIR}/${PROJECT_NAME}) - endif() + endif() endif() diff --git a/qt_gui_cpp/src/qt_gui_cpp_sip/plugin_provider.sip b/qt_gui_cpp/src/qt_gui_cpp_sip/plugin_provider.sip index 3a753c1f..45162e30 100644 --- a/qt_gui_cpp/src/qt_gui_cpp_sip/plugin_provider.sip +++ b/qt_gui_cpp/src/qt_gui_cpp_sip/plugin_provider.sip @@ -13,7 +13,7 @@ public: virtual ~PluginProvider(); - virtual QMap discover(QObject* discovery_data); + virtual QMultiMap discover(QObject* discovery_data); /** * @attention Ownership of returned PluginDescriptor's is transfered to the caller diff --git a/qt_gui_cpp/src/qt_gui_cpp_sip/recursive_plugin_provider.sip b/qt_gui_cpp/src/qt_gui_cpp_sip/recursive_plugin_provider.sip index 0bbbc9b5..43df82d5 100644 --- a/qt_gui_cpp/src/qt_gui_cpp_sip/recursive_plugin_provider.sip +++ b/qt_gui_cpp/src/qt_gui_cpp_sip/recursive_plugin_provider.sip @@ -14,7 +14,7 @@ public: virtual ~RecursivePluginProvider(); - virtual QMap discover(QObject* discovery_data); + virtual QMultiMap discover(QObject* discovery_data); virtual void shutdown(); }; diff --git a/qt_gui_cpp/src/qt_gui_cpp_sip/ros_pluginlib_plugin_provider_for_plugin_providers.sip b/qt_gui_cpp/src/qt_gui_cpp_sip/ros_pluginlib_plugin_provider_for_plugin_providers.sip index cddd9220..7c67e9d6 100644 --- a/qt_gui_cpp/src/qt_gui_cpp_sip/ros_pluginlib_plugin_provider_for_plugin_providers.sip +++ b/qt_gui_cpp/src/qt_gui_cpp_sip/ros_pluginlib_plugin_provider_for_plugin_providers.sip @@ -17,7 +17,7 @@ public: virtual ~RosPluginlibPluginProvider_ForPluginProviders(); - virtual QMap discover(QObject* discovery_data); + virtual QMultiMap discover(QObject* discovery_data); virtual QList discover_descriptors(QObject* discovery_data); diff --git a/qt_gui_cpp/src/qt_gui_cpp_sip/ros_pluginlib_plugin_provider_for_plugins.sip b/qt_gui_cpp/src/qt_gui_cpp_sip/ros_pluginlib_plugin_provider_for_plugins.sip index 4a4d5688..9b17119c 100644 --- a/qt_gui_cpp/src/qt_gui_cpp_sip/ros_pluginlib_plugin_provider_for_plugins.sip +++ b/qt_gui_cpp/src/qt_gui_cpp_sip/ros_pluginlib_plugin_provider_for_plugins.sip @@ -17,7 +17,7 @@ public: virtual ~RosPluginlibPluginProvider_ForPlugins(); - virtual QMap discover(QObject* discovery_data); + virtual QMultiMap discover(QObject* discovery_data); virtual QList discover_descriptors(QObject* discovery_data);