Skip to content

Commit bfca7ee

Browse files
committed
Adding Qt6 detection and compatibility, without breaking Qt5. -DUSE_QT6=AUTO|ON|OFF (default: AUTO; prefers Qt6 when available and CMake ≥3.16, ON forces Qt6, OFF forces Qt5). Also, a few version specific changes for API changes on Qt6, but it appears to work well.
1 parent 47b3081 commit bfca7ee

9 files changed

Lines changed: 116 additions & 17 deletions

File tree

INSTALL.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Libraries and executables have been labeled in the list below to help distinguis
5050
#### Qt 5 (libqt5)
5151
* <http://www.qt.io/qt5/> **(Library)**
5252

53-
* Qt5 is used to display video, store image data, composite images,
53+
* Qt5/Qt6 is used to display video, store image data, composite images,
5454
apply image effects, and many other utility functions,
5555
such as file system manipulation, high resolution timers, etc.
5656

@@ -201,6 +201,7 @@ Following are some of the flags you might need to set when generating your build
201201
* `-DCMAKE_PREFIX_PATH=/extra/path/to/search/for/libraries/`
202202
* `-DUSE_SYSTEM_JSONCPP=0` (default: auto if discovered)
203203
* `-DENABLE_MAGICK=0` (default: auto if discovered)
204+
* `-DUSE_QT6=AUTO|ON|OFF` (default: `AUTO`; prefers Qt6 when available and CMake ≥3.16, `ON` forces Qt6, `OFF` forces Qt5)
204205

205206
#### Options to compile bindings for a specific Python installation
206207
* `-DPYTHON_INCLUDE_DIR=/location/of/python/includes/`

doc/INSTALL-LINUX.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ list below to help distinguish between them.
4444

4545
### Qt 5 (libqt5)
4646
* http://www.qt.io/qt5/ `(Library)`
47-
* Qt5 is used to display video, store image data, composite images, apply image effects, and many other utility functions, such as file system manipulation, high resolution timers, etc...
47+
* Qt5/Qt6 is used to display video, store image data, composite images, apply image effects, and many other utility functions, such as file system manipulation, high resolution timers, etc...
48+
* Use the CMake option `-DUSE_QT6=ON|OFF|AUTO` (default AUTO) to pick a Qt major version; Qt6 builds require CMake 3.16+.
4849

4950
### CMake (cmake)
5051
* http://www.cmake.org/ `(Executable)`
@@ -166,6 +167,13 @@ software packages available to download and install.
166167
swig
167168
```
168169

170+
If you want to build against Qt6 on Ubuntu 24.04 or newer, install the Qt6 dev stack instead and configure with the default `USE_QT6=AUTO` (prefers Qt6 when available) or `-DUSE_QT6=ON` to force it:
171+
172+
```
173+
sudo apt install qt6-base-dev qt6-base-dev-tools qt6-tools-dev qt6-svg-dev
174+
```
175+
176+
169177
## Linux Build Instructions (libopenshot-audio)
170178
To compile libopenshot-audio, we need to go through a few additional steps to manually build and
171179
install it. Launch a terminal and enter:

doc/INSTALL-MAC.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ list below to help distinguish between them.
4444

4545
### Qt 5 (libqt5)
4646
* http://www.qt.io/qt5/ `(Library)`
47-
* Qt5 is used to display video, store image data, composite images, apply image effects, and many other utility functions, such as file system manipulation, high resolution timers, etc...
47+
* Qt5/Qt6 is used to display video, store image data, composite images, apply image effects, and many other utility functions, such as file system manipulation, high resolution timers, etc...
48+
* Use the CMake option `-DUSE_QT6=ON|OFF|AUTO` (default AUTO) to pick a Qt major version; Qt6 builds require CMake 3.16+.
4849

4950
### CMake (cmake)
5051
* http://www.cmake.org/ `(Executable)`

doc/INSTALL-WINDOWS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ have been labeled in the list below to help distinguish between them.
4646

4747
### Qt 5 (libqt5)
4848
* http://www.qt.io/qt5/ `(Library)`
49-
* Qt5 is used to display video, store image data, composite images, apply image effects, and many other utility functions, such as file system manipulation, high resolution timers, etc...
49+
* Qt5/Qt6 is used to display video, store image data, composite images, apply image effects, and many other utility functions, such as file system manipulation, high resolution timers, etc...
50+
* Use the CMake option `-DUSE_QT6=ON|OFF|AUTO` (default AUTO) to pick a Qt major version; Qt6 builds require CMake 3.16+.
5051

5152
### CMake (cmake)
5253
* http://www.cmake.org/ `(Executable)`

examples/CMakeLists.txt

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,45 @@
1111

1212
include(GNUInstallDirs)
1313

14-
# Dependencies
15-
find_package(Qt5 COMPONENTS Gui REQUIRED)
14+
# Qt selection matches the main library (USE_QT6 option, CMake 3.16+ needed for Qt6)
15+
set(_qt6_allowed TRUE)
16+
if(CMAKE_VERSION VERSION_LESS "3.16")
17+
set(_qt6_allowed FALSE)
18+
if(USE_QT6 STREQUAL "ON")
19+
message(FATAL_ERROR "USE_QT6=ON requires CMake 3.16 or newer")
20+
endif()
21+
endif()
22+
if(USE_QT6 STREQUAL "OFF")
23+
set(_qt6_allowed FALSE)
24+
endif()
25+
26+
set(_qt_selection "")
27+
if(USE_QT6 STREQUAL "ON")
28+
if(NOT _qt6_allowed)
29+
message(FATAL_ERROR "Qt6 support disabled by CMake version; set USE_QT6=OFF or upgrade CMake")
30+
endif()
31+
set(_qt_selection "Qt6")
32+
elseif(USE_QT6 STREQUAL "OFF")
33+
set(_qt_selection "Qt5")
34+
else()
35+
if(_qt6_allowed)
36+
find_package(Qt6 COMPONENTS Core QUIET)
37+
if(Qt6_FOUND)
38+
set(_qt_selection "Qt6")
39+
endif()
40+
endif()
41+
if(NOT _qt_selection)
42+
set(_qt_selection "Qt5")
43+
endif()
44+
endif()
45+
46+
if(_qt_selection STREQUAL "Qt6")
47+
set(QT_VERSION_MAJOR 6)
48+
else()
49+
set(QT_VERSION_MAJOR 5)
50+
endif()
51+
52+
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Gui REQUIRED)
1653

1754
############### CLI EXECUTABLES ################
1855
# Create test executable
@@ -27,7 +64,7 @@ target_compile_definitions(openshot-example PRIVATE
2764
target_link_libraries(openshot-example openshot)
2865

2966
add_executable(openshot-html-example ExampleHtml.cpp)
30-
target_link_libraries(openshot-html-example openshot Qt5::Gui)
67+
target_link_libraries(openshot-html-example openshot Qt${QT_VERSION_MAJOR}::Gui)
3168

3269
############### PLAYER EXECUTABLE ################
3370
# Create test executable

src/CMakeLists.txt

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,23 +314,67 @@ endif()
314314
### Qt Toolkit
315315
###
316316

317+
set(USE_QT6 "AUTO" CACHE STRING "Select Qt major version (AUTO, ON=Qt6, OFF=Qt5)")
318+
set_property(CACHE USE_QT6 PROPERTY STRINGS AUTO ON OFF)
319+
317320
set(_qt_components Core Gui Widgets)
318321

319322
# We also need QtSvg unless we have Resvg insetead.
320323
if(NOT HAVE_RESVG)
321324
list(APPEND _qt_components Svg)
322325
endif()
323326

324-
find_package(Qt5 COMPONENTS ${_qt_components} REQUIRED)
327+
# Qt6 packages require newer CMake; gate support so older systems still build Qt5.
328+
set(_qt6_allowed TRUE)
329+
if(CMAKE_VERSION VERSION_LESS "3.16")
330+
set(_qt6_allowed FALSE)
331+
if(USE_QT6 STREQUAL "ON")
332+
message(FATAL_ERROR "USE_QT6=ON requires CMake 3.16 or newer")
333+
endif()
334+
endif()
335+
if(USE_QT6 STREQUAL "OFF")
336+
set(_qt6_allowed FALSE)
337+
endif()
338+
339+
set(_qt_selection "")
340+
if(USE_QT6 STREQUAL "ON")
341+
if(NOT _qt6_allowed)
342+
message(FATAL_ERROR "Qt6 support disabled by CMake version; set USE_QT6=OFF or upgrade CMake")
343+
endif()
344+
set(_qt_selection "Qt6")
345+
elseif(USE_QT6 STREQUAL "OFF")
346+
set(_qt_selection "Qt5")
347+
else()
348+
if(_qt6_allowed)
349+
find_package(Qt6 COMPONENTS Core QUIET)
350+
if(Qt6_FOUND)
351+
set(_qt_selection "Qt6")
352+
endif()
353+
endif()
354+
if(NOT _qt_selection)
355+
set(_qt_selection "Qt5")
356+
endif()
357+
endif()
358+
359+
if(_qt_selection STREQUAL "Qt6")
360+
set(QT_VERSION_MAJOR 6)
361+
else()
362+
set(QT_VERSION_MAJOR 5)
363+
endif()
364+
365+
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS ${_qt_components} REQUIRED)
325366

326367
foreach(_qt_comp IN LISTS _qt_components)
327-
if(TARGET Qt5::${_qt_comp})
328-
target_link_libraries(openshot PUBLIC Qt5::${_qt_comp})
368+
if(TARGET Qt${QT_VERSION_MAJOR}::${_qt_comp})
369+
target_link_libraries(openshot PUBLIC Qt${QT_VERSION_MAJOR}::${_qt_comp})
329370
endif()
330371
endforeach()
331372

373+
string(REPLACE ";" ", " _qt_comp_list "${_qt_components}")
374+
message(STATUS "Found Qt${QT_VERSION_MAJOR} ${Qt${QT_VERSION_MAJOR}Core_VERSION_STRING} (components: ${_qt_comp_list})")
375+
332376
# Keep track of Qt version, to embed in our version header
333-
set(QT_VERSION_STR ${Qt5Core_VERSION_STRING} CACHE STRING "Qt version linked with" FORCE)
377+
set(QT_VERSION_STR ${Qt${QT_VERSION_MAJOR}Core_VERSION_STRING} CACHE STRING "Qt version linked with" FORCE)
334378
mark_as_advanced(QT_VERSION_STR)
335379

336380
################### FFMPEG #####################

src/Qt/PlayerDemo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ PlayerDemo::PlayerDemo(QWidget *parent)
4343
vbox->addWidget(menu, 0);
4444
vbox->addWidget(video, 1);
4545

46-
vbox->setMargin(0);
46+
vbox->setContentsMargins(0, 0, 0, 0);
4747
vbox->setSpacing(0);
4848
resize(600, 480);
4949

src/effects/LensFlare.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,19 @@ static QColor shifted_hsv(const QColor &base, float h_shift,
107107
float s_scale, float v_scale,
108108
float a_scale = 1.0f)
109109
{
110+
// Qt6 switched getHsvF/setHsvF to float; keep compatibility with Qt5 (qreal)
111+
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
112+
float h, s, v, a;
113+
#else
110114
qreal h, s, v, a;
115+
#endif
111116
base.getHsvF(&h, &s, &v, &a);
112117
if (s == 0.0)
113118
h = 0.0;
114-
h = std::fmod(h + h_shift + 1.0, 1.0);
115-
s = std::clamp(s * s_scale, 0.0, 1.0);
116-
v = std::clamp(v * v_scale, 0.0, 1.0);
117-
a = std::clamp(a * a_scale, 0.0, 1.0);
119+
h = static_cast<decltype(h)>(std::fmod(static_cast<double>(h + h_shift + 1.0), 1.0));
120+
s = std::clamp(s * s_scale, static_cast<decltype(s)>(0.0), static_cast<decltype(s)>(1.0));
121+
v = std::clamp(v * v_scale, static_cast<decltype(v)>(0.0), static_cast<decltype(v)>(1.0));
122+
a = std::clamp(a * a_scale, static_cast<decltype(a)>(0.0), static_cast<decltype(a)>(1.0));
118123

119124
QColor out;
120125
out.setHsvF(h, s, v, a);

tests/Caption.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ TEST_CASE("caption effect", "[libopenshot][caption]") {
6363

6464
int argc = 1;
6565
char* argv[1] = {(char*)""};
66+
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
6667
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
68+
#endif
6769
QApplication app(argc, argv);
6870

6971
QApplication::processEvents();
@@ -202,4 +204,4 @@ TEST_CASE("caption effect", "[libopenshot][caption]") {
202204

203205
// Close QApplication
204206
app.quit();
205-
}
207+
}

0 commit comments

Comments
 (0)