Skip to content

Commit 00e0460

Browse files
Qt5 and Qt6 compatibility (#157)
## Bug fix ### Fixed bug Closes #155 ### Fix applied Follows the approach proposed in #155 (comment), we can: * Remove Qt dependencies and just use the Qt version that is brought in by `gz-gui`. * Use unversioned functions for CMake. * Check at the `qml` level for the Qt version and adapt the class names with a leading underscore for qt >= 6. * Remove `LightTuning` altogether since most of its content is now available in upstream Gazebo, it has also been untested for a long time since it's not part of the default plugins but I can try to readd it if there is need for it. I tested this in a 24.04 distrobox with either rolling or jazzy and it seems to work OK, but happy to get another pair of eyes. Note that rolling has a few other issues, open-rmf/rmf_visualization#87 and gazebo failing to run (at least for me) because of an invalid command. I had to run Gazebo manually instead of using the launch file: ``` $: export GZ_SIM_RESOURCE_PATH=~/rmf_ws/install/rmf_demos_assets/share/rmf_demos_assets/models:~/rmf_ws/install/rmf_demos_maps/share/rmf_demos_maps/maps/hotel/models/ $: gz sim -r -v 3 /usr/local/google/home/lucadv/noble_ws/install/rmf_demos_maps/share/rmf_demos_maps/maps/hotel/hotel.world -z 100 ``` --------- Signed-off-by: Luca Della Vedova <lucadv@intrinsic.ai>
1 parent e4d9a36 commit 00e0460

16 files changed

Lines changed: 27 additions & 1804 deletions

File tree

rmf_building_sim_gz_plugins/CMakeLists.txt

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,6 @@ find_package(gz_rendering_vendor REQUIRED)
3737
find_package(gz-rendering REQUIRED)
3838

3939
find_package(rmf_fleet_msgs REQUIRED)
40-
find_package(Qt5
41-
COMPONENTS
42-
Core
43-
Qml
44-
Quick
45-
REQUIRED
46-
)
4740
find_package(menge_vendor REQUIRED)
4841

4942
ament_environment_hooks("${CMAKE_CURRENT_SOURCE_DIR}/hooks/${PROJECT_NAME}.dsv.in")
@@ -128,7 +121,7 @@ target_link_libraries(crowd_simulator
128121
# toggle charging
129122
###############################
130123

131-
QT5_ADD_RESOURCES(resources_RCC src/toggle_charging/toggle_charging.qrc)
124+
QT_ADD_RESOURCES(resources_RCC src/toggle_charging/toggle_charging.qrc)
132125

133126
add_library(toggle_charging SHARED ${headers_MOC}
134127
src/toggle_charging/toggle_charging.cpp
@@ -137,19 +130,17 @@ add_library(toggle_charging SHARED ${headers_MOC}
137130

138131
target_link_libraries(toggle_charging
139132
gz-sim::core
133+
gz-gui::core
140134
gz-msgs::core
141135
gz-transport::core
142-
Qt5::Core
143-
Qt5::Qml
144-
Qt5::Quick
145136
rclcpp::rclcpp
146137
)
147138

148139
###############################
149140
# toggle floors
150141
###############################
151142

152-
QT5_ADD_RESOURCES(resources_RCC src/toggle_floors/toggle_floors.qrc)
143+
QT_ADD_RESOURCES(resources_RCC src/toggle_floors/toggle_floors.qrc)
153144

154145
add_library(toggle_floors SHARED ${headers_MOC}
155146
src/toggle_floors/toggle_floors.cpp
@@ -163,9 +154,6 @@ target_link_libraries(toggle_floors
163154
gz-plugin::core
164155
gz-rendering::core
165156
gz-transport::core
166-
Qt5::Core
167-
Qt5::Qml
168-
Qt5::Quick
169157
rclcpp::rclcpp
170158
${rmf_fleet_msgs_TARGETS}
171159
)

rmf_building_sim_gz_plugins/package.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
<depend>rmf_door_msgs</depend>
1919
<depend>rmf_lift_msgs</depend>
2020
<depend>rmf_fleet_msgs</depend>
21-
<depend>libqt5-core</depend>
22-
<depend>libqt5-qml</depend>
23-
<depend>libqt5-quick</depend>
2421
<depend>menge_vendor</depend>
2522
<depend>gz_gui_vendor</depend>
2623
<depend>gz_msgs_vendor</depend>

rmf_building_sim_gz_plugins/src/toggle_charging/toggle_charging.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ void toggle_charging::LoadConfig(const tinyxml2::XMLElement* _pluginElem)
7474

7575
if (this->title.empty())
7676
this->title = "Toggle Charging";
77+
this->Context()->setContextProperty("qt_version", QVariant(QT_VERSION));
7778
}
7879

7980
void toggle_charging::OnEnableCharge(bool checked)

rmf_building_sim_gz_plugins/src/toggle_charging/toggle_charging.qml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import QtQuick.Controls 2.1
2121
import QtQuick.Controls.Material 2.2
2222
import QtQuick.Controls.Material.impl 2.2
2323
import QtQuick.Layouts 1.3
24-
import QtQuick.Controls.Styles 1.4
2524

2625
ToolBar {
2726
Layout.minimumWidth: 280
@@ -47,7 +46,11 @@ ToolBar {
4746
Layout.leftMargin: 2
4847
checked: true
4948
onClicked: {
50-
toggle_charging.OnEnableCharge(checked)
49+
if (qt_version < 0x060000) {
50+
toggle_charging.OnEnableCharge(checked)
51+
} else {
52+
_toggle_charging.OnEnableCharge(checked)
53+
}
5154
}
5255
}
5356

@@ -58,7 +61,11 @@ ToolBar {
5861
Layout.leftMargin: 2
5962
checked: false
6063
onClicked: {
61-
toggle_charging.OnEnableInstantCharge(checked)
64+
if (qt_version < 0x060000) {
65+
toggle_charging.OnEnableInstantCharge(checked)
66+
} else {
67+
_toggle_charging.OnEnableInstantCharge(checked)
68+
}
6269
}
6370
}
6471

@@ -69,9 +76,13 @@ ToolBar {
6976
Layout.leftMargin: 2
7077
checked: true
7178
onClicked: {
72-
toggle_charging.OnEnableDrain(checked)
79+
if (qt_version < 0x060000) {
80+
toggle_charging.OnEnableDrain(checked)
81+
} else {
82+
_toggle_charging.OnEnableDrain(checked)
83+
}
7384
}
7485
}
7586

7687
}
77-
}
88+
}

rmf_building_sim_gz_plugins/src/toggle_floors/toggle_floors.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ void toggle_floors::LoadConfig(const tinyxml2::XMLElement* _pluginElem)
182182
});
183183

184184
this->Context()->setContextProperty("qfloors", qfloors);
185+
this->Context()->setContextProperty("qt_version", QVariant(QT_VERSION));
185186
gz::gui::App()->findChild<
186187
gz::gui::MainWindow*>()->installEventFilter(this);
187188
}

rmf_building_sim_gz_plugins/src/toggle_floors/toggle_floors.qml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import QtQuick.Controls 2.1
2121
import QtQuick.Controls.Material 2.2
2222
import QtQuick.Controls.Material.impl 2.2
2323
import QtQuick.Layouts 1.3
24-
import QtQuick.Controls.Styles 1.4
2524

2625
ToolBar {
2726
Layout.minimumWidth: 280
@@ -46,10 +45,14 @@ ToolBar {
4645
Layout.leftMargin: 2
4746
checked: true
4847
onClicked: {
49-
toggle_floors.OnFloorChecked(text, checked)
48+
if (qt_version < 0x060000) {
49+
toggle_floors.OnFloorChecked(text, checked)
50+
} else {
51+
_toggle_floors.OnFloorChecked(text, checked)
52+
}
5053
}
5154
}
5255

5356
}
5457
}
55-
}
58+
}

rmf_robot_sim_gz_plugins/CMakeLists.txt

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ find_package(gz_sim_vendor REQUIRED)
2626
find_package(gz-sim REQUIRED)
2727
find_package(gz_plugin_vendor REQUIRED)
2828
find_package(gz-plugin REQUIRED)
29-
find_package(gz_gui_vendor REQUIRED)
30-
find_package(gz-gui REQUIRED)
3129
find_package(gz_msgs_vendor REQUIRED)
3230
find_package(gz-msgs REQUIRED)
3331
find_package(gz_transport_vendor REQUIRED)
@@ -42,13 +40,6 @@ find_package(rmf_ingestor_msgs REQUIRED)
4240
find_package(rmf_building_map_msgs REQUIRED)
4341
find_package(rmf_robot_sim_common REQUIRED)
4442
find_package(rmf_building_sim_gz_plugins REQUIRED)
45-
find_package (Qt5
46-
COMPONENTS
47-
Core
48-
Qml
49-
Quick
50-
REQUIRED
51-
)
5243

5344
ament_environment_hooks("${CMAKE_CURRENT_SOURCE_DIR}/hooks/${PROJECT_NAME}.dsv.in")
5445

@@ -148,29 +139,6 @@ target_include_directories(slotcar
148139
${rmf_building_sim_gz_plugins_INCLUDE_DIRS}
149140
)
150141

151-
###############################
152-
# LightTuning
153-
###############################
154-
155-
QT5_ADD_RESOURCES(resources_RCC src/LightTuning/LightTuning.qrc)
156-
157-
add_library(LightTuning SHARED ${headers_MOC}
158-
src/LightTuning/LightTuning.cpp
159-
${resources_RCC}
160-
)
161-
162-
target_link_libraries(LightTuning
163-
gz-gui::core
164-
gz-sim::core
165-
gz-msgs::core
166-
gz-transport::core
167-
gz-rendering::core
168-
Qt5::Core
169-
Qt5::Qml
170-
Qt5::Quick
171-
rclcpp::rclcpp
172-
)
173-
174142
###############################
175143
# Install Targets
176144
###############################
@@ -181,7 +149,6 @@ install(
181149
teleport_ingestor
182150
readonly
183151
slotcar
184-
LightTuning
185152
LIBRARY DESTINATION lib/${PROJECT_NAME}
186153
ARCHIVE DESTINATION lib/${PROJECT_NAME}
187154
)

rmf_robot_sim_gz_plugins/package.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@
2222
<depend>rmf_building_map_msgs</depend>
2323
<depend>rmf_robot_sim_common</depend>
2424
<depend>rmf_building_sim_gz_plugins</depend>
25-
<depend>libqt5-core</depend>
26-
<depend>libqt5-qml</depend>
27-
<depend>libqt5-quick</depend>
28-
<depend>gz_gui_vendor</depend>
2925
<depend>gz_msgs_vendor</depend>
3026
<depend>gz_plugin_vendor</depend>
3127
<depend>gz_rendering_vendor</depend>

rmf_robot_sim_gz_plugins/src/LightTuning/LightTuning.config

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)