[vlc-commits] [Git][videolan/vlc][master] 2 commits: qt: fix qml_test compilation

Steve Lhomme (@robUx4) gitlab at videolan.org
Fri Sep 20 05:25:34 UTC 2024



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
3ce84f71 by Pierre Lamot at 2024-09-20T05:04:50+00:00
qt: fix qml_test compilation

qml_test.moc may not be properly generated

- - - - -
7d4a3933 by Pierre Lamot at 2024-09-20T05:04:50+00:00
qml: use an event queue instead of Qt.callLater in FSM

Qt.callLater has some downsides:

* if events are rapidly emmitted, Qt.CallLater may compress them, we want to
  handle all the events here

* if the events in (CallLater) queue while the FSM is being destroyed, this will
  yield JS errors

- - - - -


5 changed files:

- modules/gui/qt/Makefile.am
- modules/gui/qt/meson.build
- modules/gui/qt/tests/qml_test.cpp
- + modules/gui/qt/tests/qml_test.hpp
- modules/gui/qt/util/qml/FSM.qml


Changes:

=====================================
modules/gui/qt/Makefile.am
=====================================
@@ -1535,9 +1535,9 @@ TESTS = base_model_test
 QML_LOG_COMPILER = $(builddir)/qml_test -input
 
 if HAVE_QT_QUICK_TEST
-qml_test_SOURCES = tests/qml_test.cpp
-qml_test_DEPENDENCIES = tests/qml_test.moc
-CLEANFILES += tests/qml_test.moc
+qml_test_SOURCES = tests/qml_test.cpp tests/qml_test.hpp
+nodist_qml_test_SOURCES = tests/qml_test.moc.cpp
+CLEANFILES += $(nodist_qml_test_SOURCES)
 qml_test_CPPFLAGS = $(libqt_plugin_la_CPPFLAGS)
 qml_test_CXXFLAGS = $(AM_CXXFLAGS) $(QT_CFLAGS) -fPIC $(CXXFLAGS_qt) ${QT_QUICK_TEST_CFLAGS} -DQUICK_TEST_SOURCE_DIR="\"${srcdir}/tests\"" -I"${builddir}/tests"
 qml_test_LDADD = $(QT_INDIRECT_LIBS) ${QT_QUICK_TEST_LIBS} $(QT_LIBS) $(LIBS_qt) libqml_module_util.a


=====================================
modules/gui/qt/meson.build
=====================================
@@ -1060,12 +1060,12 @@ if qt6_dep.found()
     test_qt6_dep = dependency('qt6', version: '=' + qt6_dep.version(), modules: ['QuickTest'], required: false)
     if test_qt6_dep.found()
         qml_test_moc = qt6.compile_moc(
-            sources : files('tests/qml_test.cpp'),
+            headers : files('tests/qml_test.hpp'),
             dependencies : [test_qt6_dep, qt6_dep]
         )
         qml_test = executable(
           'qml_test',
-          [files('tests/qml_test.cpp'), qml_test_moc],
+          [files('tests/qml_test.cpp', 'tests/qml_test.hpp'), qml_test_moc],
           qt6pre_qrc,
           build_by_default: false,
           dependencies: [test_qt6_dep, qt6_dep],


=====================================
modules/gui/qt/tests/qml_test.cpp
=====================================
@@ -17,26 +17,19 @@
 *****************************************************************************/
 
 #include <QtQuickTest>
-#include <QQmlEngine>
+#include "qml_test.hpp"
 
 // not much right now, type registration & initialisation may be required later on
 // https://doc.qt.io/qt-5/qtquicktest-index.html#executing-c-before-qml-tests
 
-class Setup : public QObject
+void Setup::qmlEngineAvailable(QQmlEngine *engine)
 {
-    Q_OBJECT
-
-public:
-    Setup() {}
-
-public slots:
-    void qmlEngineAvailable(QQmlEngine *engine)
-    {
 #if QT_VERSION < QT_VERSION_CHECK(6, 5, 0)
-        engine->addImportPath(":/qt/qml");
+    engine->addImportPath(":/qt/qml");
+#else
+    (void)engine;
 #endif
-    }
-};
+}
 
 int main(int argc, char **argv)
 {
@@ -52,5 +45,3 @@ int main(int argc, char **argv)
     Setup setup;
     return quick_test_main_with_setup(argc, argv, "qml_test", QUICK_TEST_SOURCE_DIR, &setup);
 }
-
-#include "qml_test.moc"


=====================================
modules/gui/qt/tests/qml_test.hpp
=====================================
@@ -0,0 +1,35 @@
+/*****************************************************************************
+ * Copyright (C) 2024 VLC authors and VideoLAN
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * ( at your option ) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+#ifndef QML_TEST_HPP
+#define QML_TEST_HPP
+
+#include <QObject>
+#include <QQmlEngine>
+
+class Setup : public QObject
+{
+    Q_OBJECT
+
+public:
+    using QObject::QObject;
+
+public slots:
+    void qmlEngineAvailable(QQmlEngine *engine);
+};
+
+#endif /* QML_TEST_HPP */


=====================================
modules/gui/qt/util/qml/FSM.qml
=====================================
@@ -81,6 +81,9 @@ FSMState {
 
     property bool started: false
 
+    property bool _isProcessing: false
+    property var _eventQueue: []
+
     /**
      * @param {FSMState} state state handling the event
      * @param {string} event name of the event
@@ -149,6 +152,15 @@ FSMState {
         }
     }
 
+    function _processEventQueue() {
+        fsm._isProcessing = true
+        while (fsm._eventQueue.length > 0) {
+            const e  = fsm._eventQueue.shift()
+            handleSignal(fsm, e.event, ...e.args)
+        }
+        fsm._isProcessing = false
+    }
+
     /**
      * @param {FSMState} state
      */
@@ -311,12 +323,15 @@ FSMState {
 
         for (const signalName of Object.keys(signalMap)) {
             signalMap[signalName].connect((...args) => {
-                //use callLater to ensure transitions are ordered.
-                //signal are not queued by default, this is an issue
-                //if an action/enter/exit function raise another signal
-                Qt.callLater(() => {
-                    handleSignal(fsm, signalName, ...args)
+                //events needs to be processed in order
+                //by default qml signals will process last emited first serve
+                //so we need a queue to store the call order
+                fsm._eventQueue.push({
+                    event: signalName,
+                    args: [...args]
                 })
+                if (!fsm._isProcessing)
+                    fsm._processEventQueue()
             })
         }
 



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/c208d40dcb0b57a742c03cc5307a1a16a7ccdc2b...7d4a39331fa7a986f85c70867fba3a8156070b05

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/c208d40dcb0b57a742c03cc5307a1a16a7ccdc2b...7d4a39331fa7a986f85c70867fba3a8156070b05
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list