Skip to content

Commit

Permalink
qt module: add qml module test
Browse files Browse the repository at this point in the history
  • Loading branch information
chubinou committed Jun 21, 2024
1 parent 90d42af commit 2c9b9eb
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 1 deletion.
25 changes: 25 additions & 0 deletions test cases/frameworks/4 qt/QmlCppExposed.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once
#include <QObject>
#include <QQmlEngine>

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;
};
25 changes: 25 additions & 0 deletions test cases/frameworks/4 qt/QmlCppOtherExposed.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once
#include <QObject>
#include <QQmlEngine>

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;
};
10 changes: 10 additions & 0 deletions test cases/frameworks/4 qt/QmlMain.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <QGuiApplication>
#include <QQmlApplicationEngine>

int main(int argCount, char* argVector[])
{
QGuiApplication app(argCount, argVector);
QQmlApplicationEngine engine;
engine.load("qrc:///qt/qml/Foo/Bar/QmlStuff.qml");
app.exec();
}
5 changes: 5 additions & 0 deletions test cases/frameworks/4 qt/QmlOtherStuff.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import QtQuick 2.0

Item {

}
6 changes: 6 additions & 0 deletions test cases/frameworks/4 qt/QmlSingleton.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pragma Singleton
import QtQuick

QtObject {
property int myprop: 51
}
26 changes: 26 additions & 0 deletions test cases/frameworks/4 qt/QmlStuff.qml
Original file line number Diff line number Diff line change
@@ -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
}

}
20 changes: 19 additions & 1 deletion test cases/frameworks/4 qt/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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'))
Expand Down

0 comments on commit 2c9b9eb

Please sign in to comment.