From 643828fac1c64048fedc113427b58f53d4588a2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20K=C3=BCnzel?= Date: Sun, 21 Dec 2025 14:17:00 +0100 Subject: [PATCH] Port away from QtCore5Compat Use QStringDecoder instead of the legacy QTextDecoder, if Qt6 is new enough. QStringDecoder::decoderForHtml() is available since Qt 6.4 --- .github/workflows/build-distros.yml | 10 +++++----- .github/workflows/build-msys2-mingw64.yml | 1 - CMakeLists.txt | 5 ++++- Dockerfile | 4 ++-- src/modules/qt/CMakeLists.txt | 6 +++++- src/modules/qt/filter_qtext.cpp | 11 +++++++++-- src/modules/qt/producer_qtext.cpp | 9 ++++++--- 7 files changed, 31 insertions(+), 15 deletions(-) diff --git a/.github/workflows/build-distros.yml b/.github/workflows/build-distros.yml index 13ba2e3e5..167e75969 100644 --- a/.github/workflows/build-distros.yml +++ b/.github/workflows/build-distros.yml @@ -34,7 +34,7 @@ jobs: sed -i 's/^Types: deb/Types: deb deb-src/' /etc/apt/sources.list.d/ubuntu.sources DEBIAN_FRONTEND=noninteractive apt-get -qq update DEBIAN_FRONTEND=noninteractive apt-get -yqq build-dep mlt - DEBIAN_FRONTEND=noninteractive apt-get -yqq install cmake qt6-base-dev libqt6svg6-dev libqt6core5compat6-dev + DEBIAN_FRONTEND=noninteractive apt-get -yqq install cmake qt6-base-dev libqt6svg6-dev - name: ubuntu-22.04 image: ubuntu:22.04 setup_script: | @@ -54,7 +54,7 @@ jobs: echo 'deb-src http://deb.debian.org/debian testing main' >> /etc/apt/sources.list apt-get -qq update apt-get -yqq build-dep mlt - apt-get -yqq install cmake qt6-base-dev libqt6svg6-dev libqt6core5compat6-dev + apt-get -yqq install cmake qt6-base-dev libqt6svg6-dev - name: debian-stable image: debian:stable setup_script: | @@ -62,7 +62,7 @@ jobs: echo 'deb http://deb.debian.org/debian bookworm-backports main' >> /etc/apt/sources.list apt-get -qq update apt-get -yqq build-dep mlt - apt-get -yqq install cmake qt6-base-dev libqt6svg6-dev libqt6core5compat6-dev + apt-get -yqq install cmake qt6-base-dev libqt6svg6-dev - name: fedora-42 image: fedora:42 setup_script: | @@ -71,7 +71,7 @@ jobs: yasm gavl-devel libsamplerate-devel libxml2-devel \ ladspa-devel jack-audio-connection-kit-devel sox-devel \ SDL2-devel fftw-devel frei0r-devel gtk2-devel libexif-devel \ - qt6-qtbase-devel qt6-qt5compat-devel qt6-qtsvg-devel \ + qt6-qtbase-devel qt6-qtsvg-devel \ libtheora-devel libvorbis-devel libvdpau-devel \ libsoup-devel liboil-devel python-devel alsa-lib \ pulseaudio-libs-devel gcc-c++ cmake ffmpeg-free-devel \ @@ -84,7 +84,7 @@ jobs: yasm gavl-devel libsamplerate-devel libxml2-devel \ ladspa-devel jack-audio-connection-kit-devel sox-devel \ SDL2-devel fftw-devel frei0r-devel gtk2-devel libexif-devel \ - qt6-qtbase-devel qt6-qt5compat-devel qt6-qtsvg-devel \ + qt6-qtbase-devel qt6-qtsvg-devel \ libtheora-devel libvorbis-devel libvdpau-devel \ libsoup-devel liboil-devel python-devel alsa-lib \ pulseaudio-libs-devel gcc-c++ cmake ffmpeg-free-devel \ diff --git a/.github/workflows/build-msys2-mingw64.yml b/.github/workflows/build-msys2-mingw64.yml index eb6f492ff..2417926cd 100644 --- a/.github/workflows/build-msys2-mingw64.yml +++ b/.github/workflows/build-msys2-mingw64.yml @@ -49,7 +49,6 @@ jobs: mingw-w64-x86_64-potrace mingw-w64-x86_64-python-pip mingw-w64-x86_64-qt5-base - mingw-w64-x86_64-qt6-5compat mingw-w64-x86_64-qt6-base mingw-w64-x86_64-qt6-svg mingw-w64-x86_64-rubberband diff --git a/CMakeLists.txt b/CMakeLists.txt index 3369dc98d..3171fade3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -306,7 +306,10 @@ endif() # It is necessary to look for Qt6 before Qt5, otherwise there will # be a conflict with the targets in case both are enabled if(MOD_QT6) - find_package(Qt6 REQUIRED COMPONENTS Core Gui Xml SvgWidgets Core5Compat) + find_package(Qt6 REQUIRED COMPONENTS Core Gui Xml SvgWidgets) + if(Qt6_VERSION VERSION_LESS 6.4.0) + find_package(Qt6 REQUIRED COMPONENTS Core5Compat) + endif() list(APPEND MLT_SUPPORTED_COMPONENTS qt6) endif() diff --git a/Dockerfile b/Dockerfile index fbc0a94ab..958181774 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,7 +11,7 @@ FROM base AS build RUN apt-get install -yqq wget git automake autoconf libtool intltool g++ yasm nasm \ swig libgavl-dev libsamplerate0-dev libxml2-dev ladspa-sdk libjack-dev \ libsox-dev libsdl2-dev libgtk2.0-dev libsoup2.4-dev \ - qt6-base-dev qt6-5compat-dev qt6-svg-dev libarchive-dev libmp3lame-dev \ + qt6-base-dev qt6-svg-dev libarchive-dev libmp3lame-dev \ libexif-dev libtheora-dev libvorbis-dev python3-dev cmake xutils-dev \ libegl1-mesa-dev libeigen3-dev libfftw3-dev libvdpau-dev meson ninja-build @@ -29,7 +29,7 @@ FROM base RUN apt-get install -yqq dumb-init \ libsamplerate0 libxml2 libjack0 \ libsdl2-2.0-0 libgtk2.0-0 libsoup2.4-1 \ - libqt6core5compat6 libqt6svgwidgets6 libqt6xml6 qt6-image-formats-plugins libarchive13 \ + libqt6svgwidgets6 libqt6xml6 qt6-image-formats-plugins libarchive13 \ libtheora0 libvorbis0a python3 \ libegl1 libfftw3-double3 libvdpau1 \ # Additional runtime libs \ diff --git a/src/modules/qt/CMakeLists.txt b/src/modules/qt/CMakeLists.txt index c176e5202..902def305 100644 --- a/src/modules/qt/CMakeLists.txt +++ b/src/modules/qt/CMakeLists.txt @@ -68,8 +68,12 @@ function(mlt_add_qt_module ARG_TARGET) if(ARG_QT_VERSION EQUAL 6) target_link_libraries(${ARG_TARGET} PRIVATE Qt6::SvgWidgets - Qt6::Core5Compat ) + if(Qt6Core5Compat_FOUND) + target_link_libraries(${ARG_TARGET} PRIVATE + Qt6::Core5Compat + ) + endif() else() target_link_libraries(${ARG_TARGET} PRIVATE Qt${ARG_QT_VERSION}::Svg diff --git a/src/modules/qt/filter_qtext.cpp b/src/modules/qt/filter_qtext.cpp index 5bd80ff3e..f3ecd882f 100644 --- a/src/modules/qt/filter_qtext.cpp +++ b/src/modules/qt/filter_qtext.cpp @@ -27,8 +27,10 @@ #include #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) #include -#else +#elif QT_VERSION < QT_VERSION_CHECK(6, 4, 0) #include +#else +#include #endif #include "typewriter.h" @@ -394,10 +396,15 @@ static QTextDocument *get_rich_text(mlt_properties properties, double width, dou QFile file(resource); if (file.open(QFile::ReadOnly)) { QByteArray data = file.readAll(); - QTextCodec *codec = QTextCodec::codecForHtml(data); doc = new QTextDocument; doc->setPageSize(QSizeF(width, height)); +#if QT_VERSION < QT_VERSION_CHECK(6, 4, 0) + QTextCodec *codec = QTextCodec::codecForHtml(data); doc->setHtml(codec->toUnicode(data)); +#else + QStringDecoder decoder = QStringDecoder::decoderForHtml(data); + doc->setHtml(decoder(data)); +#endif mlt_properties_set_data(properties, "QTextDocument", doc, diff --git a/src/modules/qt/producer_qtext.cpp b/src/modules/qt/producer_qtext.cpp index 935ec60c5..ac3fb59d5 100644 --- a/src/modules/qt/producer_qtext.cpp +++ b/src/modules/qt/producer_qtext.cpp @@ -32,8 +32,7 @@ #include #include #else -#include -#include +#include #endif static void close_qimg(void *qimg) @@ -161,12 +160,16 @@ static void generate_qpath(mlt_properties producer_properties) // Make the path empty *qPath = QPainterPath(); qPath->setFillRule(Qt::WindingFill); - +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // Get the strings to display QTextCodec *codec = QTextCodec::codecForName(encoding); QTextDecoder *decoder = codec->makeDecoder(); QString s = decoder->toUnicode(text); delete decoder; +#else + auto decoder = QStringDecoder(encoding); + QString s = decoder(text); +#endif QStringList lines = s.split("\n"); // Configure the font