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.

This commit is contained in:
Jonathan Thomas
2025-12-17 22:59:25 -06:00
parent 47b308122f
commit bfca7ee8ad
9 changed files with 116 additions and 17 deletions

View File

@@ -50,7 +50,7 @@ Libraries and executables have been labeled in the list below to help distinguis
#### Qt 5 (libqt5)
* <http://www.qt.io/qt5/> **(Library)**
* Qt5 is used to display video, store image data, composite images,
* 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.
@@ -201,6 +201,7 @@ Following are some of the flags you might need to set when generating your build
* `-DCMAKE_PREFIX_PATH=/extra/path/to/search/for/libraries/`
* `-DUSE_SYSTEM_JSONCPP=0` (default: auto if discovered)
* `-DENABLE_MAGICK=0` (default: auto if discovered)
* `-DUSE_QT6=AUTO|ON|OFF` (default: `AUTO`; prefers Qt6 when available and CMake ≥3.16, `ON` forces Qt6, `OFF` forces Qt5)
#### Options to compile bindings for a specific Python installation
* `-DPYTHON_INCLUDE_DIR=/location/of/python/includes/`

View File

@@ -44,7 +44,8 @@ list below to help distinguish between them.
### Qt 5 (libqt5)
* http://www.qt.io/qt5/ `(Library)`
* 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...
* 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...
* Use the CMake option `-DUSE_QT6=ON|OFF|AUTO` (default AUTO) to pick a Qt major version; Qt6 builds require CMake 3.16+.
### CMake (cmake)
* http://www.cmake.org/ `(Executable)`
@@ -166,6 +167,13 @@ software packages available to download and install.
swig
```
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:
```
sudo apt install qt6-base-dev qt6-base-dev-tools qt6-tools-dev qt6-svg-dev
```
## Linux Build Instructions (libopenshot-audio)
To compile libopenshot-audio, we need to go through a few additional steps to manually build and
install it. Launch a terminal and enter:

View File

@@ -44,7 +44,8 @@ list below to help distinguish between them.
### Qt 5 (libqt5)
* http://www.qt.io/qt5/ `(Library)`
* 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...
* 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...
* Use the CMake option `-DUSE_QT6=ON|OFF|AUTO` (default AUTO) to pick a Qt major version; Qt6 builds require CMake 3.16+.
### CMake (cmake)
* http://www.cmake.org/ `(Executable)`

View File

@@ -46,7 +46,8 @@ have been labeled in the list below to help distinguish between them.
### Qt 5 (libqt5)
* http://www.qt.io/qt5/ `(Library)`
* 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...
* 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...
* Use the CMake option `-DUSE_QT6=ON|OFF|AUTO` (default AUTO) to pick a Qt major version; Qt6 builds require CMake 3.16+.
### CMake (cmake)
* http://www.cmake.org/ `(Executable)`

View File

@@ -11,8 +11,45 @@
include(GNUInstallDirs)
# Dependencies
find_package(Qt5 COMPONENTS Gui REQUIRED)
# Qt selection matches the main library (USE_QT6 option, CMake 3.16+ needed for Qt6)
set(_qt6_allowed TRUE)
if(CMAKE_VERSION VERSION_LESS "3.16")
set(_qt6_allowed FALSE)
if(USE_QT6 STREQUAL "ON")
message(FATAL_ERROR "USE_QT6=ON requires CMake 3.16 or newer")
endif()
endif()
if(USE_QT6 STREQUAL "OFF")
set(_qt6_allowed FALSE)
endif()
set(_qt_selection "")
if(USE_QT6 STREQUAL "ON")
if(NOT _qt6_allowed)
message(FATAL_ERROR "Qt6 support disabled by CMake version; set USE_QT6=OFF or upgrade CMake")
endif()
set(_qt_selection "Qt6")
elseif(USE_QT6 STREQUAL "OFF")
set(_qt_selection "Qt5")
else()
if(_qt6_allowed)
find_package(Qt6 COMPONENTS Core QUIET)
if(Qt6_FOUND)
set(_qt_selection "Qt6")
endif()
endif()
if(NOT _qt_selection)
set(_qt_selection "Qt5")
endif()
endif()
if(_qt_selection STREQUAL "Qt6")
set(QT_VERSION_MAJOR 6)
else()
set(QT_VERSION_MAJOR 5)
endif()
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Gui REQUIRED)
############### CLI EXECUTABLES ################
# Create test executable
@@ -27,7 +64,7 @@ target_compile_definitions(openshot-example PRIVATE
target_link_libraries(openshot-example openshot)
add_executable(openshot-html-example ExampleHtml.cpp)
target_link_libraries(openshot-html-example openshot Qt5::Gui)
target_link_libraries(openshot-html-example openshot Qt${QT_VERSION_MAJOR}::Gui)
############### PLAYER EXECUTABLE ################
# Create test executable

View File

@@ -314,6 +314,9 @@ endif()
### Qt Toolkit
###
set(USE_QT6 "AUTO" CACHE STRING "Select Qt major version (AUTO, ON=Qt6, OFF=Qt5)")
set_property(CACHE USE_QT6 PROPERTY STRINGS AUTO ON OFF)
set(_qt_components Core Gui Widgets)
# We also need QtSvg unless we have Resvg insetead.
@@ -321,16 +324,57 @@ if(NOT HAVE_RESVG)
list(APPEND _qt_components Svg)
endif()
find_package(Qt5 COMPONENTS ${_qt_components} REQUIRED)
# Qt6 packages require newer CMake; gate support so older systems still build Qt5.
set(_qt6_allowed TRUE)
if(CMAKE_VERSION VERSION_LESS "3.16")
set(_qt6_allowed FALSE)
if(USE_QT6 STREQUAL "ON")
message(FATAL_ERROR "USE_QT6=ON requires CMake 3.16 or newer")
endif()
endif()
if(USE_QT6 STREQUAL "OFF")
set(_qt6_allowed FALSE)
endif()
set(_qt_selection "")
if(USE_QT6 STREQUAL "ON")
if(NOT _qt6_allowed)
message(FATAL_ERROR "Qt6 support disabled by CMake version; set USE_QT6=OFF or upgrade CMake")
endif()
set(_qt_selection "Qt6")
elseif(USE_QT6 STREQUAL "OFF")
set(_qt_selection "Qt5")
else()
if(_qt6_allowed)
find_package(Qt6 COMPONENTS Core QUIET)
if(Qt6_FOUND)
set(_qt_selection "Qt6")
endif()
endif()
if(NOT _qt_selection)
set(_qt_selection "Qt5")
endif()
endif()
if(_qt_selection STREQUAL "Qt6")
set(QT_VERSION_MAJOR 6)
else()
set(QT_VERSION_MAJOR 5)
endif()
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS ${_qt_components} REQUIRED)
foreach(_qt_comp IN LISTS _qt_components)
if(TARGET Qt5::${_qt_comp})
target_link_libraries(openshot PUBLIC Qt5::${_qt_comp})
if(TARGET Qt${QT_VERSION_MAJOR}::${_qt_comp})
target_link_libraries(openshot PUBLIC Qt${QT_VERSION_MAJOR}::${_qt_comp})
endif()
endforeach()
string(REPLACE ";" ", " _qt_comp_list "${_qt_components}")
message(STATUS "Found Qt${QT_VERSION_MAJOR} ${Qt${QT_VERSION_MAJOR}Core_VERSION_STRING} (components: ${_qt_comp_list})")
# Keep track of Qt version, to embed in our version header
set(QT_VERSION_STR ${Qt5Core_VERSION_STRING} CACHE STRING "Qt version linked with" FORCE)
set(QT_VERSION_STR ${Qt${QT_VERSION_MAJOR}Core_VERSION_STRING} CACHE STRING "Qt version linked with" FORCE)
mark_as_advanced(QT_VERSION_STR)
################### FFMPEG #####################

View File

@@ -43,7 +43,7 @@ PlayerDemo::PlayerDemo(QWidget *parent)
vbox->addWidget(menu, 0);
vbox->addWidget(video, 1);
vbox->setMargin(0);
vbox->setContentsMargins(0, 0, 0, 0);
vbox->setSpacing(0);
resize(600, 480);

View File

@@ -107,14 +107,19 @@ static QColor shifted_hsv(const QColor &base, float h_shift,
float s_scale, float v_scale,
float a_scale = 1.0f)
{
// Qt6 switched getHsvF/setHsvF to float; keep compatibility with Qt5 (qreal)
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
float h, s, v, a;
#else
qreal h, s, v, a;
#endif
base.getHsvF(&h, &s, &v, &a);
if (s == 0.0)
h = 0.0;
h = std::fmod(h + h_shift + 1.0, 1.0);
s = std::clamp(s * s_scale, 0.0, 1.0);
v = std::clamp(v * v_scale, 0.0, 1.0);
a = std::clamp(a * a_scale, 0.0, 1.0);
h = static_cast<decltype(h)>(std::fmod(static_cast<double>(h + h_shift + 1.0), 1.0));
s = std::clamp(s * s_scale, static_cast<decltype(s)>(0.0), static_cast<decltype(s)>(1.0));
v = std::clamp(v * v_scale, static_cast<decltype(v)>(0.0), static_cast<decltype(v)>(1.0));
a = std::clamp(a * a_scale, static_cast<decltype(a)>(0.0), static_cast<decltype(a)>(1.0));
QColor out;
out.setHsvF(h, s, v, a);

View File

@@ -63,7 +63,9 @@ TEST_CASE("caption effect", "[libopenshot][caption]") {
int argc = 1;
char* argv[1] = {(char*)""};
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
QApplication app(argc, argv);
QApplication::processEvents();
@@ -202,4 +204,4 @@ TEST_CASE("caption effect", "[libopenshot][caption]") {
// Close QApplication
app.quit();
}
}