From 2c9b9ebd1beb8713a2bd476005e67be4661c22c7 Mon Sep 17 00:00:00 2001 From: Pierre Lamot Date: Thu, 6 Jun 2024 18:05:45 +0200 Subject: [PATCH] qt module: add qml module test --- test cases/frameworks/4 qt/QmlCppExposed.hpp | 25 ++++++++++++++++++ .../frameworks/4 qt/QmlCppOtherExposed.hpp | 25 ++++++++++++++++++ test cases/frameworks/4 qt/QmlMain.cpp | 10 +++++++ test cases/frameworks/4 qt/QmlOtherStuff.qml | 5 ++++ test cases/frameworks/4 qt/QmlSingleton.qml | 6 +++++ test cases/frameworks/4 qt/QmlStuff.qml | 26 +++++++++++++++++++ test cases/frameworks/4 qt/meson.build | 20 +++++++++++++- 7 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 test cases/frameworks/4 qt/QmlCppExposed.hpp create mode 100644 test cases/frameworks/4 qt/QmlCppOtherExposed.hpp create mode 100644 test cases/frameworks/4 qt/QmlMain.cpp create mode 100644 test cases/frameworks/4 qt/QmlOtherStuff.qml create mode 100644 test cases/frameworks/4 qt/QmlSingleton.qml create mode 100644 test cases/frameworks/4 qt/QmlStuff.qml diff --git a/test cases/frameworks/4 qt/QmlCppExposed.hpp b/test cases/frameworks/4 qt/QmlCppExposed.hpp new file mode 100644 index 000000000000..6198aff556dc --- /dev/null +++ b/test cases/frameworks/4 qt/QmlCppExposed.hpp @@ -0,0 +1,25 @@ +#pragma once +#include +#include + +class QmlCppExposed : public QObject +{ + Q_OBJECT + QML_ELEMENT + Q_PROPERTY(int foo READ getFoo WRITE setFoo NOTIFY fooChanged) + +public: + inline int getFoo() const { return m_foo; } + inline void setFoo(int value) { + if (value == m_foo) + return; + m_foo = value; + emit fooChanged(); + } + +signals: + void fooChanged(); + +private: + int m_foo = 42; +}; diff --git a/test cases/frameworks/4 qt/QmlCppOtherExposed.hpp b/test cases/frameworks/4 qt/QmlCppOtherExposed.hpp new file mode 100644 index 000000000000..2d764c26b0cb --- /dev/null +++ b/test cases/frameworks/4 qt/QmlCppOtherExposed.hpp @@ -0,0 +1,25 @@ +#pragma once +#include +#include + +class QmlCppOtherExposed : public QObject +{ + Q_OBJECT + QML_ELEMENT + Q_PROPERTY(int foo READ getFoo WRITE setFoo NOTIFY fooChanged) + +public: + inline int getFoo() const { return m_foo; } + inline void setFoo(int value) { + if (value == m_foo) + return; + m_foo = value; + emit fooChanged(); + } + +signals: + void fooChanged(); + +private: + int m_foo = 42; +}; diff --git a/test cases/frameworks/4 qt/QmlMain.cpp b/test cases/frameworks/4 qt/QmlMain.cpp new file mode 100644 index 000000000000..16794fef3a27 --- /dev/null +++ b/test cases/frameworks/4 qt/QmlMain.cpp @@ -0,0 +1,10 @@ +#include +#include + +int main(int argCount, char* argVector[]) +{ + QGuiApplication app(argCount, argVector); + QQmlApplicationEngine engine; + engine.load("qrc:///qt/qml/Foo/Bar/QmlStuff.qml"); + app.exec(); +} diff --git a/test cases/frameworks/4 qt/QmlOtherStuff.qml b/test cases/frameworks/4 qt/QmlOtherStuff.qml new file mode 100644 index 000000000000..9c36e13c5bfc --- /dev/null +++ b/test cases/frameworks/4 qt/QmlOtherStuff.qml @@ -0,0 +1,5 @@ +import QtQuick 2.0 + +Item { + +} diff --git a/test cases/frameworks/4 qt/QmlSingleton.qml b/test cases/frameworks/4 qt/QmlSingleton.qml new file mode 100644 index 000000000000..ae9ec0959beb --- /dev/null +++ b/test cases/frameworks/4 qt/QmlSingleton.qml @@ -0,0 +1,6 @@ +pragma Singleton +import QtQuick + +QtObject { + property int myprop: 51 +} diff --git a/test cases/frameworks/4 qt/QmlStuff.qml b/test cases/frameworks/4 qt/QmlStuff.qml new file mode 100644 index 000000000000..40829b5a6da7 --- /dev/null +++ b/test cases/frameworks/4 qt/QmlStuff.qml @@ -0,0 +1,26 @@ +import QtQuick 2.0 +import Foo.Bar 1.0 + +Window { + width: 640 + height: 200 + visible: true + title: qsTr("Sample") + + QmlCppExposed { + id: cppExposed + } + Text { + id: cppExposedTxt + text: "value from Cpp exposed " + cppExposed.foo + " (should be 42)" + } + Text { + id: singletonTxt + anchors.top: cppExposedTxt.bottom + text: "value from Singleton exposed " + QmlSingleton.myprop + " (should be 51)" + } + QmlOtherStuff { + anchors.top: singletonTxt.bottom + } + +} diff --git a/test cases/frameworks/4 qt/meson.build b/test cases/frameworks/4 qt/meson.build index 54cd7cb9bac3..ff994fa2cf47 100644 --- a/test cases/frameworks/4 qt/meson.build +++ b/test cases/frameworks/4 qt/meson.build @@ -6,7 +6,7 @@ project('qt4, qt5, and qt6 build test', 'cpp', subdir('mocdep') qt5_modules = ['Widgets'] -qt6_modules = ['Widgets'] +qt6_modules = ['Widgets', 'Qml'] foreach qt : ['qt4', 'qt5', 'qt6'] qt_modules = ['Core', 'Gui'] if qt == 'qt5' @@ -165,6 +165,24 @@ foreach qt : ['qt4', 'qt5', 'qt6'] subdir('subfolder') endif + if qt == 'qt6' + qmlmodule = qtmodule.qml_module( + 'qmlmodule', + 'Foo.Bar', + '1.0', + qml_sources: files('QmlStuff.qml', 'QmlOtherStuff.qml'), + qml_singletons: files('QmlSingleton.qml'), + imports: ['QtQuick/2.0', 'QtQuick.Templates'], + resources_prefix: '/qt/qml', + moc_headers: files('QmlCppExposed.hpp', 'QmlCppOtherExposed.hpp'), + dependencies: [qtdep], + ) + qmlplugin = executable(qt + '_qmlmodule', + sources : ['QmlMain.cpp', qmlmodule], + dependencies : qtdep) + endif + + # Check we can apply a version constraint accept_versions = ['>=@0@'.format(qtdep.version()), '<@0@'.format(qtdep.version()[0].to_int() + 1)] dependency(qt, modules: qt_modules, version: accept_versions, method : get_option('method'))