From: APTX Date: Sun, 16 Oct 2022 06:44:39 +0000 (+0900) Subject: Initial Qt6 port X-Git-Url: https://gitweb.tyo.aptx.org/?a=commitdiff_plain;ds=inline;p=aniplayer.git Initial Qt6 port Note that a complate Qt6 port will require QML changes. I don't know of a way to have QML be compatible with both Qt5 and Qt6. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index c2e0f48..70f8012 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,10 @@ include(CMakeDependentOption) project(AniPlayer) -set(QT_MIN_VERSION "5.3.0") + + +option(WITH_QT6 "Build with Qt6" OFF) +add_feature_info(BuildWithQt6 WITH_QT6 "Qt6 build") option(WITH_DESKTOP_UI "Build default QML desktop UI" ON) add_feature_info(QmlDesktopUI WITH_DESKTOP_UI "default desktop UI, using QML") @@ -26,6 +29,18 @@ endif() cmake_dependent_option(USE_SHARED_DLIB "Use shared dlib" OFF "WITH_FEATURE_ANNOTATIONS" OFF) +if (WITH_FEATURE_LOCALMYLIST AND WITH_QT6) + message(FATAL_ERROR "LocalMyList is currently not supported with Qt6") +endif() + +if (WITH_QT6) + set(QT_PACKAGE "Qt6") + set(QT_MIN_VERSION "6.4.0") +else() + set(QT_PACKAGE "Qt5") + set(QT_MIN_VERSION "5.3.0") +endif() + add_subdirectory(pluginapi) add_subdirectory(core) add_subdirectory(backendplugins) diff --git a/backendplugins/backend_mpv/CMakeLists.txt b/backendplugins/backend_mpv/CMakeLists.txt index e075d7a..e8fdfe2 100644 --- a/backendplugins/backend_mpv/CMakeLists.txt +++ b/backendplugins/backend_mpv/CMakeLists.txt @@ -1,16 +1,18 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON) project(backend_mpv) -find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS +find_package(${QT_PACKAGE} ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS Core Gui Qml Quick + OpenGL ) set(backend_mpv_LIBS - Qt5::Core - Qt5::Gui + ${QT_PACKAGE}::Core + ${QT_PACKAGE}::Gui + ${QT_PACKAGE}::OpenGL pluginapi # TODO find_package this mpv diff --git a/backendplugins/backend_mpv/qthelper.hpp b/backendplugins/backend_mpv/qthelper.hpp index 5ea7885..a7f178c 100644 --- a/backendplugins/backend_mpv/qthelper.hpp +++ b/backendplugins/backend_mpv/qthelper.hpp @@ -140,7 +140,11 @@ private: // "QVariant::Type(obsolete), the return value should be interpreted // as QMetaType::Type." // So a cast really seems to be needed to avoid warnings (urgh). +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + return static_cast(v.typeId()) == static_cast(t); +#else return static_cast(v.type()) == static_cast(t); +#endif } void set(mpv_node *dst, const QVariant &src) { if (test_type(src, QMetaType::QString)) { diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 6109dc4..e0449f8 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -7,7 +7,7 @@ set(core_VERSION "0.4.0") add_subdirectory("qtsingleapplication") -find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS +find_package(${QT_PACKAGE} ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS Core Gui Widgets @@ -15,14 +15,12 @@ find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS Quick ) -find_package(LocalMyList CONFIG REQUIRED) - set(core_LIBS - Qt5::Core - Qt5::Gui - Qt5::Widgets - Qt5::Qml - Qt5::Quick + ${QT_PACKAGE}::Core + ${QT_PACKAGE}::Gui + ${QT_PACKAGE}::Widgets + ${QT_PACKAGE}::Qml + ${QT_PACKAGE}::Quick pluginapi qtsingleapplication ) @@ -71,7 +69,7 @@ if (WIN32) ) elseif(UNIX AND WITH_FEATURE_DBUS) add_definitions(-DWITH_FEATURE_DBUS) - find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS + find_package(${QT_PACKAGE} ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS DBus ) set(core_LIBS ${core_LIBS} diff --git a/core/qtsingleapplication/CMakeLists.txt b/core/qtsingleapplication/CMakeLists.txt index 30a3d46..6a3d177 100644 --- a/core/qtsingleapplication/CMakeLists.txt +++ b/core/qtsingleapplication/CMakeLists.txt @@ -1,16 +1,16 @@ set(CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE ON) project(qtsingleapplication) -find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS +find_package(${QT_PACKAGE} ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS Core Widgets Network ) set(qtsingleapplication_LIBS - Qt5::Core - Qt5::Widgets - Qt5::Network + ${QT_PACKAGE}::Core + ${QT_PACKAGE}::Widgets + ${QT_PACKAGE}::Network ) set(qtsingleapplication_SOURCES diff --git a/core/qtsingleapplication/qtlocalpeer.cpp b/core/qtsingleapplication/qtlocalpeer.cpp index e4cf804..31fb205 100644 --- a/core/qtsingleapplication/qtlocalpeer.cpp +++ b/core/qtsingleapplication/qtlocalpeer.cpp @@ -37,11 +37,11 @@ ** ****************************************************************************/ - #include "qtlocalpeer.h" #include -#include #include +#include +#include #if defined(Q_OS_WIN) #include @@ -75,11 +75,16 @@ QtLocalPeer::QtLocalPeer(QObject* parent, const QString &appId) #endif prefix = id.section(QLatin1Char('/'), -1); } - prefix.remove(QRegExp("[^a-zA-Z]")); + prefix.remove(QRegularExpression("[^a-zA-Z]")); prefix.truncate(6); QByteArray idc = id.toUtf8(); - quint16 idNum = qChecksum(idc.constData(), idc.size()); + quint16 idNum = +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + qChecksum(QByteArrayView{idc.constData(), idc.size()}); +#else + qChecksum(idc.constData(), idc.size()); +#endif socketName = QLatin1String("qtsingleapp-") + prefix + QLatin1Char('-') + QString::number(idNum, 16); diff --git a/featureplugins/feature_annotations/CMakeLists.txt b/featureplugins/feature_annotations/CMakeLists.txt index a55d4dc..afb6f76 100644 --- a/featureplugins/feature_annotations/CMakeLists.txt +++ b/featureplugins/feature_annotations/CMakeLists.txt @@ -1,7 +1,7 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON) project(feature_annotations) -find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS +find_package(${QT_PACKAGE} ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS Core Gui Concurrent @@ -18,9 +18,9 @@ else() endif() set(feature_annotations_LIBS - Qt5::Core - Qt5::Gui - Qt5::Concurrent + ${QT_PACKAGE}::Core + ${QT_PACKAGE}::Gui + ${QT_PACKAGE}::Concurrent ${DLIB_LIBRARY_NAME} pluginapi ) diff --git a/featureplugins/feature_localmylist/CMakeLists.txt b/featureplugins/feature_localmylist/CMakeLists.txt index aff2038..89a0bed 100644 --- a/featureplugins/feature_localmylist/CMakeLists.txt +++ b/featureplugins/feature_localmylist/CMakeLists.txt @@ -1,14 +1,14 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON) project(feature_localmylist) -find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS +find_package(${QT_PACKAGE} ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS Core ) find_package(LocalMyList CONFIG REQUIRED) set(feature_localmylist_LIBS - Qt5::Core + ${QT_PACKAGE}::Core pluginapi # TODO find_package this LocalMyList::LocalMyList diff --git a/pluginapi/CMakeLists.txt b/pluginapi/CMakeLists.txt index 7522ec1..4d2f49e 100644 --- a/pluginapi/CMakeLists.txt +++ b/pluginapi/CMakeLists.txt @@ -10,8 +10,8 @@ set(pluginapi_PUBLIC_HEADERS ) add_library(pluginapi INTERFACE ${pluginapi_PUBLIC_HEADERS}) -find_package(Qt5 COMPONENTS Core) -target_link_libraries(pluginapi INTERFACE Qt5::Core) +find_package(${QT_PACKAGE} COMPONENTS Core) +target_link_libraries(pluginapi INTERFACE ${QT_PACKAGE}::Core) install(FILES ${pluginapi_PUBLIC_HEADERS} DESTINATION include/aniplayer diff --git a/uiplugins/ui_desktop_qml_default/CMakeLists.txt b/uiplugins/ui_desktop_qml_default/CMakeLists.txt index 7df7b9a..41d491b 100644 --- a/uiplugins/ui_desktop_qml_default/CMakeLists.txt +++ b/uiplugins/ui_desktop_qml_default/CMakeLists.txt @@ -1,7 +1,7 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON) project(ui_desktop_qml_default) -find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS +find_package(${QT_PACKAGE} ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS Core Gui Qml @@ -9,13 +9,18 @@ find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS ) set(ui_desktop_qml_default_LIBS - Qt5::Core - Qt5::Gui - Qt5::Qml - Qt5::Quick + ${QT_PACKAGE}::Core + ${QT_PACKAGE}::Gui + ${QT_PACKAGE}::Qml + ${QT_PACKAGE}::Quick pluginapi ) +if (WITH_QT6) + find_package(${QT_PACKAGE} ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS QuickControls2) + set(ui_desktop_qml_default_LIBS ${ui_desktop_qml_default_LIBS} ${QT_PACKAGE}::QuickControls2) +endif() + set(ui_desktop_qml_default_SOURCES uidesktopqmldefault.cpp timeformatter.cpp @@ -30,7 +35,9 @@ set(ui_desktop_qml_default_HEADERS ) set(CMAKE_AUTOMOC ON) -set(CMAKE_AUTOUIC ON) +# POSSIBLE CMAKE BUG +# the "ui_" prefix makes cmake think there should be a .ui file to run uic on. +set(CMAKE_AUTOUIC OFF) set(CMAKE_AUTORCC ON) add_library(ui_desktop_qml_default MODULE diff --git a/uiplugins/ui_desktop_qml_default/uidesktopqmldefault.cpp b/uiplugins/ui_desktop_qml_default/uidesktopqmldefault.cpp index c38d5f0..fb91d6d 100644 --- a/uiplugins/ui_desktop_qml_default/uidesktopqmldefault.cpp +++ b/uiplugins/ui_desktop_qml_default/uidesktopqmldefault.cpp @@ -23,9 +23,17 @@ UiDesktopQmlDefaultInstance::UiDesktopQmlDefaultInstance(QObject *player, qCDebug(uidqdCategory, "Player Added"); engine->load( QUrl(QStringLiteral("qrc:/ui_desktop_qml_default/qml/main.qml"))); + m_engine = engine; + m_player = player; qCDebug(uidqdCategory, "QML engine loaded"); } +UiDesktopQmlDefaultInstance::~UiDesktopQmlDefaultInstance() { + // Ensure the UI is deleted before the player + delete m_engine; + delete m_player; +} + UiInstance *UiDesktopQmlDefault::createUi(QObject *player, QObject *settings, QObject *parent) { return new UiDesktopQmlDefaultInstance{player, settings, parent}; diff --git a/uiplugins/ui_desktop_qml_default/uidesktopqmldefault.h b/uiplugins/ui_desktop_qml_default/uidesktopqmldefault.h index 928a779..8108375 100644 --- a/uiplugins/ui_desktop_qml_default/uidesktopqmldefault.h +++ b/uiplugins/ui_desktop_qml_default/uidesktopqmldefault.h @@ -11,6 +11,11 @@ class UI_DESKTOP_QML_DEFAULTSHARED_EXPORT UiDesktopQmlDefaultInstance public: explicit UiDesktopQmlDefaultInstance(QObject *player, QObject *settings, QObject *parent = nullptr); + ~UiDesktopQmlDefaultInstance() override; + +private: + QObject *m_engine; + QObject *m_player; }; class UI_DESKTOP_QML_DEFAULTSHARED_EXPORT UiDesktopQmlDefault