Skip to content

Commit a7f35c6

Browse files
iche033azeey
andauthored
Migrate to Qt6 (#2832)
Signed-off-by: Addisu Z. Taddese <[email protected]> Signed-off-by: Ian Chen <[email protected]> Co-authored-by: Addisu Z. Taddese <[email protected]>
1 parent 3fa5abe commit a7f35c6

File tree

83 files changed

+700
-687
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+700
-687
lines changed

.github/ci/packages.apt

+12-12
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,18 @@ python3-gz-transport15
3030
python3-pybind11
3131
python3-pytest
3232
python3-sdformat15
33-
qml-module-qt-labs-folderlistmodel
34-
qml-module-qt-labs-settings
35-
qml-module-qtgraphicaleffects
36-
qml-module-qtqml-models2
37-
qml-module-qtquick-controls
38-
qml-module-qtquick-controls2
39-
qml-module-qtquick-dialogs
40-
qml-module-qtquick-layouts
41-
qml-module-qtquick2
42-
qtbase5-dev
43-
qtdeclarative5-dev
44-
qtquickcontrols2-5-dev
33+
qml6-module-qt-labs-folderlistmodel
34+
qml6-module-qt-labs-settings
35+
qml6-module-qt5compat-graphicaleffects
36+
qml6-module-qtqml-models
37+
qml6-module-qtquick-controls
38+
qml6-module-qtquick-dialogs
39+
qml6-module-qtquick-layouts
40+
qml6-module-qtquick
41+
qt6-5compat-dev
42+
qt6-base-dev
43+
qt6-base-private-dev
44+
qt6-declarative-dev
4545
uuid-dev
4646
xvfb
4747
x11-utils

CMakeLists.txt

+14-2
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,25 @@ set(GZ_FUEL_TOOLS_VER ${gz-fuel_tools10_VERSION_MAJOR})
113113
#--------------------------------------
114114
# Find gz-gui
115115
gz_find_package(gz-gui REQUIRED)
116-
gz_find_package (Qt5
116+
117+
set(QT_MAJOR_VERSION 6)
118+
set(QT_MINOR_VERSION 4)
119+
gz_find_package (Qt${QT_MAJOR_VERSION}
120+
VERSION ${QT_MAJOR_VERSION}.${QT_MINOR_VERSION}
117121
COMPONENTS
118122
Core
119123
Quick
120124
QuickControls2
121125
REQUIRED
122-
PKGCONFIG "Qt5Core Qt5Quick Qt5QuickControls2")
126+
PKGCONFIG "Qt${QT_MAJOR_VERSION}Core Qt${QT_MAJOR_VERSION}Quick Qt${QT_MAJOR_VERSION}QuickControls2")
127+
128+
set(CMAKE_AUTOMOC TRUE)
129+
set(CMAKE_AUTOUIC TRUE)
130+
set(CMAKE_AUTORCC TRUE)
131+
if(POLICY CMP0100)
132+
cmake_policy(SET CMP0100 NEW)
133+
endif()
134+
123135

124136
#--------------------------------------
125137
# Find gz-physics

examples/plugin/gui_system_plugin/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ set(CMAKE_AUTOMOC ON)
1010

1111
find_package(gz-sim REQUIRED COMPONENTS gui)
1212

13-
QT5_ADD_RESOURCES(resources_RCC ${PROJECT_NAME}.qrc)
13+
QT_ADD_RESOURCES(resources_RCC ${PROJECT_NAME}.qrc)
1414

1515
add_library(${PROJECT_NAME} SHARED
1616
${PROJECT_NAME}.cc

examples/plugin/gui_system_plugin/GuiSystemPlugin.qml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ import QtQuick.Controls 2.2
2020
// Display custom property text
2121
Text {
2222
width: 300
23-
text: GuiSystemPlugin.customProperty
23+
text: _GuiSystemPlugin.customProperty
2424
}

examples/plugin/rendering_plugins/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ set(CMAKE_AUTOMOC ON)
1616

1717
find_package(gz-gui REQUIRED)
1818

19-
QT5_ADD_RESOURCES(resources_RCC ${GUI_PLUGIN}.qrc)
19+
QT_ADD_RESOURCES(resources_RCC ${GUI_PLUGIN}.qrc)
2020

2121
add_library(${GUI_PLUGIN} SHARED
2222
${GUI_PLUGIN}.cc

examples/plugin/rendering_plugins/RenderingGuiPlugin.qml

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Rectangle {
2626
Button {
2727
text: qsTr("Random GUI color!")
2828
onClicked: {
29-
RenderingGuiPlugin.RandomColor();
29+
_RenderingGuiPlugin.RandomColor();
3030
}
3131
anchors.horizontalCenter: parent.horizontalCenter
3232
anchors.verticalCenter: parent.verticalCenter

src/gui/CMakeLists.txt

+7-4
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ set(CMAKE_AUTORCC ON)
2424

2525
# CMake AUTOMOC does not generate moc_*.cpp files automatically for headers
2626
# located in different directories than the containing .cc file. For Qt header
27-
# files in `include/gz/sim/gui`, we use qt5_wrap_cpp instead. There is
27+
# files in `include/gz/sim/gui`, we use qt_wrap_cpp instead. There is
2828
# no need to add entries for Qt header files in `src/gui/`.
29-
qt5_wrap_cpp(gui_sources
29+
qt_wrap_cpp(gui_sources
3030
${PROJECT_SOURCE_DIR}/include/gz/sim/gui/GuiSystem.hh
3131
)
3232

@@ -51,8 +51,11 @@ target_link_libraries(${gui_target}
5151
gz-gui::gz-gui
5252
gz-transport::gz-transport
5353
gz-utils${GZ_UTILS_VER}::gz-utils${GZ_UTILS_VER}
54-
${Qt5Core_LIBRARIES}
55-
${Qt5Widgets_LIBRARIES}
54+
Qt::Core
55+
Qt::Qml
56+
Qt::Quick
57+
Qt::QuickControls2
58+
Qt::Widgets
5659
)
5760

5861
set(CMAKE_AUTOMOC OFF)

src/gui/Gui.cc

+6-2
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,8 @@ std::unique_ptr<gz::gui::Application> createGui(
434434

435435
// Let QML files use C++ functions and properties
436436
auto context = new QQmlContext(app->Engine()->rootContext());
437-
context->setContextProperty("AboutDialogHandler", aboutDialogHandler);
438-
context->setContextProperty("GuiFileHandler", guiFileHandler);
437+
context->setContextProperty("_AboutDialogHandler", aboutDialogHandler);
438+
context->setContextProperty("_GuiFileHandler", guiFileHandler);
439439

440440
// Instantiate GazeboDrawer.qml file into a component
441441
QQmlComponent component(app->Engine(), ":/Gazebo/GazeboDrawer.qml");
@@ -452,6 +452,10 @@ std::unique_ptr<gz::gui::Application> createGui(
452452
}
453453
else
454454
{
455+
if (component.isError())
456+
{
457+
qWarning() << component.errors();
458+
}
455459
gzerr << "Failed to instantiate custom drawer, drawer will be empty"
456460
<< std::endl;
457461
}

src/gui/GuiRunner.cc

+4-4
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ using namespace sim;
4747

4848
// Register SerializedStepMap to the Qt meta type system so we can pass objects
4949
// of this type in QMetaObject::invokeMethod
50-
Q_DECLARE_METATYPE(msgs::SerializedStepMap)
50+
Q_DECLARE_METATYPE(gz::msgs::SerializedStepMap)
5151

5252
/////////////////////////////////////////////////
5353
class gz::sim::GuiRunner::Implementation
@@ -109,7 +109,7 @@ class gz::sim::GuiRunner::Implementation
109109
GuiRunner::GuiRunner(const std::string &_worldName)
110110
: dataPtr(utils::MakeUniqueImpl<Implementation>())
111111
{
112-
qRegisterMetaType<msgs::SerializedStepMap>();
112+
qRegisterMetaType<gz::msgs::SerializedStepMap>();
113113

114114
this->setProperty("worldName", QString::fromStdString(_worldName));
115115

@@ -263,7 +263,7 @@ void GuiRunner::OnStateAsyncService(const msgs::SerializedStepMap &_res)
263263
// ensures that only one thread has access to the ecm and updateInfo
264264
// variables.
265265
QMetaObject::invokeMethod(this, "OnStateQt", Qt::QueuedConnection,
266-
Q_ARG(msgs::SerializedStepMap, _res));
266+
Q_ARG(gz::msgs::SerializedStepMap, _res));
267267
this->dataPtr->receivedInitialState = true;
268268

269269
// todo(anyone) store reqSrv string in a member variable and use it here
@@ -289,7 +289,7 @@ void GuiRunner::OnState(const msgs::SerializedStepMap &_msg)
289289
// ensures that only one thread has access to the ecm and updateInfo
290290
// variables.
291291
QMetaObject::invokeMethod(this, "OnStateQt", Qt::QueuedConnection,
292-
Q_ARG(msgs::SerializedStepMap, _msg));
292+
Q_ARG(gz::msgs::SerializedStepMap, _msg));
293293
}
294294

295295
/////////////////////////////////////////////////

src/gui/GuiRunner.hh

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class GZ_SIM_GUI_VISIBLE GuiRunner : public QObject
6767

6868
/// \brief Called by the Qt thread to update the ECM with new state
6969
/// \param[in] _msg New state message.
70-
private: Q_INVOKABLE void OnStateQt(const msgs::SerializedStepMap &_msg);
70+
private: Q_INVOKABLE void OnStateQt(const gz::msgs::SerializedStepMap &_msg);
7171

7272
/// \brief Update the plugins.
7373
private: Q_INVOKABLE void UpdatePlugins();

src/gui/Gui_TEST.cc

+7
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,11 @@ TEST_F(GuiTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(PathManager))
179179
/////////////////////////////////////////////////
180180
TEST_F(GuiTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(QuickStart))
181181
{
182+
// \todo(iche033)
183+
// Gui crashes when closing main window. Occurs on Ubuntu CI with Qt6.
184+
// Re-enable once fixed.
185+
GTEST_SKIP();
186+
182187
common::Console::SetVerbosity(4);
183188
gzdbg << "Start test" << std::endl;
184189

@@ -252,6 +257,8 @@ TEST_F(GuiTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(QuickStart))
252257
// Close the quick start window
253258
gzdbg << "Closing the quickstart window" << std::endl;
254259
ASSERT_EQ(1, gui::App()->allWindows().count());
260+
while (!gui::App()->allWindows()[0]->isExposed())
261+
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
255262
gui::App()->allWindows()[0]->close();
256263

257264
gzdbg << "Waiting for main window" << std::endl;

src/gui/plugins/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ function(gz_add_gui_library library_name)
2323

2424
cmake_parse_arguments(gz_add_gui_library "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
2525

26-
QT5_WRAP_CPP(${library_name}_headers_MOC ${gz_add_gui_library_QT_HEADERS})
27-
QT5_ADD_RESOURCES(${library_name}_RCC ${library_name}.qrc)
26+
QT_WRAP_CPP(${library_name}_headers_MOC ${gz_add_gui_library_QT_HEADERS})
27+
QT_ADD_RESOURCES(${library_name}_RCC ${library_name}.qrc)
2828

2929
if(MSVC)
3030
# Warning #4251 is the "dll-interface" warning that tells you when types

0 commit comments

Comments
 (0)