]> Some of my projects - aniplayer.git/commitdiff
Initial Qt6 port master
authorAPTX <redacted>
Sun, 16 Oct 2022 06:44:39 +0000 (15:44 +0900)
committerAPTX <redacted>
Sun, 16 Oct 2022 06:44:49 +0000 (15:44 +0900)
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.

12 files changed:
CMakeLists.txt
backendplugins/backend_mpv/CMakeLists.txt
backendplugins/backend_mpv/qthelper.hpp
core/CMakeLists.txt
core/qtsingleapplication/CMakeLists.txt
core/qtsingleapplication/qtlocalpeer.cpp
featureplugins/feature_annotations/CMakeLists.txt
featureplugins/feature_localmylist/CMakeLists.txt
pluginapi/CMakeLists.txt
uiplugins/ui_desktop_qml_default/CMakeLists.txt
uiplugins/ui_desktop_qml_default/uidesktopqmldefault.cpp
uiplugins/ui_desktop_qml_default/uidesktopqmldefault.h

index c2e0f48..70f8012 100644 (file)
@@ -5,7 +5,10 @@ include(CMakeDependentOption)
 
 project(AniPlayer)
 
 
 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")
 
 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)
 
 
 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)
 add_subdirectory(pluginapi)
 add_subdirectory(core)
 add_subdirectory(backendplugins)
index e075d7a..e8fdfe2 100644 (file)
@@ -1,16 +1,18 @@
 set(CMAKE_INCLUDE_CURRENT_DIR ON)
 project(backend_mpv)
 
 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
     Core
     Gui
     Qml
     Quick
+    OpenGL
 )
 
 set(backend_mpv_LIBS
 )
 
 set(backend_mpv_LIBS
-    Qt5::Core
-    Qt5::Gui
+    ${QT_PACKAGE}::Core
+    ${QT_PACKAGE}::Gui
+    ${QT_PACKAGE}::OpenGL
     pluginapi
     # TODO find_package this
     mpv
     pluginapi
     # TODO find_package this
     mpv
index 5ea7885..a7f178c 100644 (file)
@@ -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).
         // "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<int>(v.typeId()) == static_cast<int>(t);
+#else
         return static_cast<int>(v.type()) == static_cast<int>(t);
         return static_cast<int>(v.type()) == static_cast<int>(t);
+#endif
     }
     void set(mpv_node *dst, const QVariant &src) {
         if (test_type(src, QMetaType::QString)) {
     }
     void set(mpv_node *dst, const QVariant &src) {
         if (test_type(src, QMetaType::QString)) {
index 6109dc4..e0449f8 100644 (file)
@@ -7,7 +7,7 @@ set(core_VERSION "0.4.0")
 
 add_subdirectory("qtsingleapplication")
 
 
 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
     Core
     Gui
     Widgets
@@ -15,14 +15,12 @@ find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS
     Quick
 )
 
     Quick
 )
 
-find_package(LocalMyList CONFIG REQUIRED)
-
 set(core_LIBS
 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
 )
     pluginapi
     qtsingleapplication
 )
@@ -71,7 +69,7 @@ if (WIN32)
     )
 elseif(UNIX AND WITH_FEATURE_DBUS)
     add_definitions(-DWITH_FEATURE_DBUS)
     )
 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}
         DBus
     )
     set(core_LIBS ${core_LIBS}
index 30a3d46..6a3d177 100644 (file)
@@ -1,16 +1,16 @@
 set(CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE ON)
 project(qtsingleapplication)
 
 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
     Core
     Widgets
     Network
 )
 
 set(qtsingleapplication_LIBS
-    Qt5::Core
-    Qt5::Widgets
-    Qt5::Network
+    ${QT_PACKAGE}::Core
+    ${QT_PACKAGE}::Widgets
+    ${QT_PACKAGE}::Network
 )
 
 set(qtsingleapplication_SOURCES
 )
 
 set(qtsingleapplication_SOURCES
index e4cf804..31fb205 100644 (file)
 **
 ****************************************************************************/
 
 **
 ****************************************************************************/
 
-
 #include "qtlocalpeer.h"
 #include <QCoreApplication>
 #include "qtlocalpeer.h"
 #include <QCoreApplication>
-#include <QTime>
 #include <QDataStream>
 #include <QDataStream>
+#include <QRegularExpression>
+#include <QTime>
 
 #if defined(Q_OS_WIN)
 #include <QLibrary>
 
 #if defined(Q_OS_WIN)
 #include <QLibrary>
@@ -75,11 +75,16 @@ QtLocalPeer::QtLocalPeer(QObject* parent, const QString &appId)
 #endif
         prefix = id.section(QLatin1Char('/'), -1);
     }
 #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();
     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);
 
     socketName = QLatin1String("qtsingleapp-") + prefix
                  + QLatin1Char('-') + QString::number(idNum, 16);
 
index a55d4dc..afb6f76 100644 (file)
@@ -1,7 +1,7 @@
 set(CMAKE_INCLUDE_CURRENT_DIR ON)
 project(feature_annotations)
 
 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
     Core
     Gui
     Concurrent
@@ -18,9 +18,9 @@ else()
 endif()
 
 set(feature_annotations_LIBS
 endif()
 
 set(feature_annotations_LIBS
-    Qt5::Core
-    Qt5::Gui
-    Qt5::Concurrent
+    ${QT_PACKAGE}::Core
+    ${QT_PACKAGE}::Gui
+    ${QT_PACKAGE}::Concurrent
     ${DLIB_LIBRARY_NAME}
     pluginapi
 )
     ${DLIB_LIBRARY_NAME}
     pluginapi
 )
index aff2038..89a0bed 100644 (file)
@@ -1,14 +1,14 @@
 set(CMAKE_INCLUDE_CURRENT_DIR ON)
 project(feature_localmylist)
 
 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
     Core
 )
 
 find_package(LocalMyList CONFIG REQUIRED)
 
 set(feature_localmylist_LIBS
-    Qt5::Core
+    ${QT_PACKAGE}::Core
     pluginapi
     # TODO find_package this
     LocalMyList::LocalMyList
     pluginapi
     # TODO find_package this
     LocalMyList::LocalMyList
index 7522ec1..4d2f49e 100644 (file)
@@ -10,8 +10,8 @@ set(pluginapi_PUBLIC_HEADERS
 )
 
 add_library(pluginapi INTERFACE ${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
 
 install(FILES ${pluginapi_PUBLIC_HEADERS}
     DESTINATION include/aniplayer
index 7df7b9a..41d491b 100644 (file)
@@ -1,7 +1,7 @@
 set(CMAKE_INCLUDE_CURRENT_DIR ON)
 project(ui_desktop_qml_default)
 
 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
     Core
     Gui
     Qml
@@ -9,13 +9,18 @@ find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS
 )
 
 set(ui_desktop_qml_default_LIBS
 )
 
 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
 )
 
     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
 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_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
 set(CMAKE_AUTORCC ON)
 
 add_library(ui_desktop_qml_default MODULE
index c38d5f0..fb91d6d 100644 (file)
@@ -23,9 +23,17 @@ UiDesktopQmlDefaultInstance::UiDesktopQmlDefaultInstance(QObject *player,
   qCDebug(uidqdCategory, "Player Added");\r
   engine->load(\r
       QUrl(QStringLiteral("qrc:/ui_desktop_qml_default/qml/main.qml")));\r
   qCDebug(uidqdCategory, "Player Added");\r
   engine->load(\r
       QUrl(QStringLiteral("qrc:/ui_desktop_qml_default/qml/main.qml")));\r
+  m_engine = engine;\r
+  m_player = player;\r
   qCDebug(uidqdCategory, "QML engine loaded");\r
 }\r
 \r
   qCDebug(uidqdCategory, "QML engine loaded");\r
 }\r
 \r
+UiDesktopQmlDefaultInstance::~UiDesktopQmlDefaultInstance() {\r
+  // Ensure the UI is deleted before the player\r
+  delete m_engine;\r
+  delete m_player;\r
+}\r
+\r
 UiInstance *UiDesktopQmlDefault::createUi(QObject *player, QObject *settings,\r
                                           QObject *parent) {\r
   return new UiDesktopQmlDefaultInstance{player, settings, parent};\r
 UiInstance *UiDesktopQmlDefault::createUi(QObject *player, QObject *settings,\r
                                           QObject *parent) {\r
   return new UiDesktopQmlDefaultInstance{player, settings, parent};\r
index 928a779..8108375 100644 (file)
@@ -11,6 +11,11 @@ class UI_DESKTOP_QML_DEFAULTSHARED_EXPORT UiDesktopQmlDefaultInstance
 public:\r
   explicit UiDesktopQmlDefaultInstance(QObject *player, QObject *settings,\r
                                        QObject *parent = nullptr);\r
 public:\r
   explicit UiDesktopQmlDefaultInstance(QObject *player, QObject *settings,\r
                                        QObject *parent = nullptr);\r
+  ~UiDesktopQmlDefaultInstance() override;\r
+\r
+private:\r
+  QObject *m_engine;\r
+  QObject *m_player;\r
 };\r
 \r
 class UI_DESKTOP_QML_DEFAULTSHARED_EXPORT UiDesktopQmlDefault\r
 };\r
 \r
 class UI_DESKTOP_QML_DEFAULTSHARED_EXPORT UiDesktopQmlDefault\r