Skip to content

Commit 2697844

Browse files
authored
Upgrade from qt5 to qt6 (#222)
* Upgrade from qt5 to qt6 Signed-off-by: Raül <raulojeda@eprosima.com> * C++17 and skip QtStandaloneTestTemplateProject Signed-off-by: Raül <raulojeda@eprosima.com> * Fix thread safety issues in Qt GUI operations Signed-off-by: Raül <raulojeda@eprosima.com> * Remove skip QtStandaloneTestTemplateProject in multiplatform colcon build Signed-off-by: Raül <raulojeda@eprosima.com> * Move Qt installation outside workspace to prevent test project builds Signed-off-by: Raül <raulojeda@eprosima.com> * Change from Qt 6.10.1 to 6.8.3 Signed-off-by: Raül <raulojeda@eprosima.com> --------- Signed-off-by: Raül <raulojeda@eprosima.com>
1 parent 0daec96 commit 2697844

14 files changed

Lines changed: 79 additions & 50 deletions

File tree

.github/workflows/reusable-ubuntu-ci.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,9 @@ jobs:
103103
- name: Install Qt
104104
uses: eProsima/eProsima-CI/external/install_qt@v0
105105
with:
106-
version: '5.15.2'
107-
dir: '${{ github.workspace }}/qt_installation/'
106+
version: '6.8.3'
107+
arch: 'linux_gcc_64'
108+
dir: '/opt/qt_installation/'
108109
modules: 'qtcharts'
109110
setup-python: 'false'
110111

.github/workflows/reusable-windows-ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ jobs:
122122
- name: Install Qt
123123
uses: eProsima/eProsima-CI/external/install_qt@v0
124124
with:
125-
version: '5.15.2'
126-
dir: '${{ github.workspace }}/qt_installation/'
127-
arch: 'win64_msvc2019_64'
125+
version: '6.8.3'
126+
dir: '/opt/qt_installation/'
127+
arch: 'win64_msvc2022_64'
128128
modules: 'qtcharts'
129129
setup-python: 'false'
130130

CMakeLists.txt

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,14 @@ else()
4343
endif()
4444

4545
project("ShapesDemo")
46+
4647
set(PROJECT_NAME_STYLED "ShapesDemo")
4748
set(PROJECT_NAME_LARGE "Shapes Demo")
4849
string(TOUPPER "${PROJECT_NAME}" PROJECT_NAME_UPPER)
4950
set(${PROJECT_NAME}_DESCRIPTION_SUMMARY "Shapes Demo for eProsima Fast DDS")
5051
set(${PROJECT_NAME}_DESCRIPTION "eProsima ${PROJECT_NAME_LARGE} library provides publication/subscription communication using RTPS protocol.")
5152

52-
message(STATUS "Configuring ${PROJECT_NAME_LAGE}")
53+
message(STATUS "Configuring ${PROJECT_NAME_LARGE}")
5354

5455
###############################################################################
5556
# Warning level
@@ -150,9 +151,11 @@ endif()
150151
###############################################################################
151152
# Compile
152153
###############################################################################
153-
find_package(Qt5Core 5.9 REQUIRED)
154-
find_package(Qt5Gui REQUIRED)
155-
find_package(Qt5Widgets REQUIRED)
154+
find_package(Qt6 6.8.3 REQUIRED COMPONENTS Core Gui Widgets)
155+
156+
set(CMAKE_AUTOMOC ON)
157+
set(CMAKE_AUTOUIC ON)
158+
set(CMAKE_AUTORCC ON)
156159

157160
set( MOC_HEADERS
158161
include/eprosimashapesdemo/qt/DrawArea.h
@@ -176,11 +179,6 @@ set( RESOURCES
176179
images/eprosimalogo.qrc
177180
)
178181

179-
180-
QT5_WRAP_UI( UI_HEADERS ${UIS} )
181-
QT5_WRAP_CPP( MOC_SRCS ${MOC_HEADERS} )
182-
QT5_ADD_RESOURCES( RSCS ${RESOURCES} )
183-
184182
set(CMAKE_INCLUDE_CURRENT_DIR ON)
185183
set(CMAKE_AUTOUIC_SEARCH_PATHS forms)
186184

@@ -202,6 +200,9 @@ set( SHAPESDEMO_SOURCES
202200
src/shapesdemo/ShapeSubscriber.cpp
203201
types/ShapePubSubTypes.cxx
204202
types/ShapeTypeObjectSupport.cxx
203+
${MOC_HEADERS}
204+
${UIS}
205+
${RESOURCES}
205206
)
206207

207208
if(BUILD_ROS_COMPONENTS)
@@ -212,9 +213,9 @@ if(BUILD_ROS_COMPONENTS)
212213
endif()
213214

214215
if(WIN32)
215-
add_executable(${PROJECT_NAME} WIN32 ${SHAPESDEMO_SOURCES} ${MOC_SRCS} ${UI_HEADERS} ${RSCS} )
216+
add_executable(${PROJECT_NAME} WIN32 ${SHAPESDEMO_SOURCES})
216217
else()
217-
add_executable(${PROJECT_NAME} ${SHAPESDEMO_SOURCES} ${MOC_SRCS} ${UI_HEADERS} ${RSCS} )
218+
add_executable(${PROJECT_NAME} ${SHAPESDEMO_SOURCES})
218219
endif()
219220

220221
target_compile_definitions(${PROJECT_NAME} PRIVATE -D${SHAPESVERSION})
@@ -227,9 +228,9 @@ endif()
227228
target_link_libraries(${PROJECT_NAME}
228229
fastcdr
229230
fastdds
230-
Qt5::Core
231-
Qt5::Widgets
232-
Qt5::Gui)
231+
Qt6::Core
232+
Qt6::Widgets
233+
Qt6::Gui)
233234

234235
###############################################################################
235236
# Install

cmake/common/check_configuration.cmake

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,49 +16,64 @@
1616
# along with eProsima Fast DDS Shapes Demo. If not, see <https://www.gnu.org/licenses/>.
1717

1818
macro(check_stdcxx)
19-
# Check C++11
19+
# Check C++17 (updated for Qt6 compatibility)
2020
include(CheckCXXCompilerFlag)
2121
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANG OR
2222
CMAKE_CXX_COMPILER_ID MATCHES "Clang")
23-
check_cxx_compiler_flag(-std=c++14 SUPPORTS_CXX14)
23+
check_cxx_compiler_flag(-std=c++17 SUPPORTS_CXX17)
24+
set(HAVE_CXX17 0)
2425
set(HAVE_CXX14 0)
2526
set(HAVE_CXX1Y 0)
2627
set(HAVE_CXX11 0)
2728
set(HAVE_CXX0X 0)
28-
if(SUPPORTS_CXX14)
29-
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-std=c++14>)
29+
if(SUPPORTS_CXX17)
30+
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-std=c++17>)
31+
set(HAVE_CXX17 1)
3032
set(HAVE_CXX14 1)
3133
set(HAVE_CXX1Y 1)
3234
set(HAVE_CXX11 1)
3335
set(HAVE_CXX0X 1)
3436
else()
35-
check_cxx_compiler_flag(-std=c++1y SUPPORTS_CXX1Y)
36-
if(SUPPORTS_CXX1Y)
37-
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-std=c++1y>)
37+
check_cxx_compiler_flag(-std=c++14 SUPPORTS_CXX14)
38+
if(SUPPORTS_CXX14)
39+
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-std=c++14>)
40+
set(HAVE_CXX14 1)
3841
set(HAVE_CXX1Y 1)
3942
set(HAVE_CXX11 1)
4043
set(HAVE_CXX0X 1)
4144
else()
42-
check_cxx_compiler_flag(-std=c++11 SUPPORTS_CXX11)
43-
if(SUPPORTS_CXX11)
44-
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-std=c++11>)
45+
check_cxx_compiler_flag(-std=c++1y SUPPORTS_CXX1Y)
46+
if(SUPPORTS_CXX1Y)
47+
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-std=c++1y>)
48+
set(HAVE_CXX1Y 1)
4549
set(HAVE_CXX11 1)
4650
set(HAVE_CXX0X 1)
4751
else()
48-
check_cxx_compiler_flag(-std=c++0x SUPPORTS_CXX0X)
49-
if(SUPPORTS_CXX0X)
50-
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-std=c++0x>)
52+
check_cxx_compiler_flag(-std=c++11 SUPPORTS_CXX11)
53+
if(SUPPORTS_CXX11)
54+
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-std=c++11>)
55+
set(HAVE_CXX11 1)
5156
set(HAVE_CXX0X 1)
5257
else()
53-
set(HAVE_CXX0X 0)
58+
check_cxx_compiler_flag(-std=c++0x SUPPORTS_CXX0X)
59+
if(SUPPORTS_CXX0X)
60+
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-std=c++0x>)
61+
set(HAVE_CXX0X 1)
62+
else()
63+
set(HAVE_CXX0X 0)
64+
endif()
5465
endif()
5566
endif()
5667
endif()
5768
endif()
5869
elseif(MSVC OR MSVC_IDE)
70+
set(HAVE_CXX17 1)
71+
set(HAVE_CXX14 1)
5972
set(HAVE_CXX11 1)
6073
set(HAVE_CXX0X 1)
6174
else()
75+
set(HAVE_CXX17 0)
76+
set(HAVE_CXX14 0)
6277
set(HAVE_CXX11 0)
6378
set(HAVE_CXX0X 0)
6479
endif()

include/eprosimashapesdemo/qt/mainwindow.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ class MainWindow : public QMainWindow
5454
{
5555
Q_OBJECT
5656

57+
signals:
58+
void messageReady(QString str, bool addtostatus);
59+
5760
public:
5861

5962
explicit MainWindow(
@@ -135,6 +138,7 @@ private slots:
135138
void on_actionInteroperability_Troubleshooting_triggered();
136139

137140
public slots:
141+
void addMessageToOutputThreadSafe(const QString& str, bool addtostatus = false);
138142

139143
void on_actionStart_triggered();
140144

include/eprosimashapesdemo/shapesdemo/ShapePublisher.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class ShapePublisher : public DataWriterListener
117117
}
118118

119119
Shape m_shape;
120-
QMutex m_mutex;
120+
QRecursiveMutex m_mutex;
121121
bool isInitialized;
122122
bool hasWritten;
123123
MainWindow* m_mainWindow;

include/eprosimashapesdemo/shapesdemo/ShapeSubscriber.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class ShapeSubscriber
120120
}
121121

122122
bool hasReceived;
123-
QMutex m_mutex;
123+
QRecursiveMutex m_mutex;
124124
ShapeHistory m_shapeHistory;
125125
TYPESHAPE m_shapeType;
126126
ContentFilterSelector* mp_contentFilter;

include/eprosimashapesdemo/shapesdemo/ShapesDemo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ class ShapesDemo
230230

231231
ShapesDemoOptions m_options;
232232
MainWindow* m_mainWindow;
233-
QMutex m_mutex;
233+
QRecursiveMutex m_mutex;
234234
TypeSupport m_type;
235235
#ifdef ENABLE_ROS_COMPONENTS
236236
TypeSupport m_ros_type;

include/eprosimashapesdemo/shapesdemo/ShapesDemoLogConsumer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ class ShapesDemoLogConsumer : public LogConsumer
5959
print_message(stream_, entry, false);
6060
print_context(stream_, entry, false);
6161

62-
// Add message to Output tab
63-
main_window_->addMessageToOutput(QString(stream_.str().c_str()));
62+
// Add thread-safe message to Output tab
63+
main_window_->addMessageToOutputThreadSafe(QString:: fromStdString(stream_.str()), false);
6464

6565
// Clear stringstream
6666
stream_.str("");

src/qt/DrawArea.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ void DrawArea::paintEvent(
6767
{
6868
Q_UNUSED(e);
6969
QStyleOption opt;
70-
opt.init(this);
70+
opt.initFrom(this);
7171

7272
QPainter painter(this);
7373
style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this);

0 commit comments

Comments
 (0)