Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qml modules #13304

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
qt module: add qml module test
  • Loading branch information
chubinou committed Aug 9, 2024
commit e8e84651af925dad289eb37d100148244211c68f
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();
}
6 changes: 5 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,10 @@ foreach qt : ['qt4', 'qt5', 'qt6']
subdir('subfolder')
endif

if qt == 'qt6'
subdir('qml')
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
5 changes: 5 additions & 0 deletions test cases/frameworks/4 qt/qml/Basic.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import QtQuick 2.0

Item {
property int ok: 1
}
5 changes: 5 additions & 0 deletions test cases/frameworks/4 qt/qml/Internal.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import QtQuick

Item {
property int ok: 5
}
42 changes: 42 additions & 0 deletions test cases/frameworks/4 qt/qml/Main.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import QtQuick
import My.Module1 as M1
import My.Module2 as M2
import My.Module3 as M3
import My.Module4 as M4

Item {

M1.Basic { id: b1 }
M1.Thing { id: t1 }
M1.QmlCppExposed { id: c1 }

M2.Thing { id: t2 }

M3.Basic { id: b3 }

M4.BasicAliased { id: b4 }

Component.onCompleted: {
function checkClass(display, id, value) {
if (id.ok !== value) {
console.log(display, "KO got", id.ok, "expected", value)
Qt.exit(-1)
}
else
console.log(display, "OK")
}

checkClass("M1.Basic", b1, 1);
checkClass("M1.Thing", t1, 2);
checkClass("M1.QmlCppExposed", c1, 3);
checkClass("M1.QmlSingleton", M1.QmlSingleton, 5);

checkClass("M2.Thing", t2, 2);

checkClass("M3.Basic", b3, 1);

checkClass("M4.BasicAliased", b4, 1);

Qt.quit()
}
}
25 changes: 25 additions & 0 deletions test cases/frameworks/4 qt/qml/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 ok READ getOk WRITE setOk NOTIFY okChanged)

public:
inline int getOk() const { return m_ok; }
inline void setOk(int value) {
if (value == m_ok)
return;
m_ok = value;
emit okChanged();
}

signals:
void okChanged();

private:
int m_ok = 3;
};
25 changes: 25 additions & 0 deletions test cases/frameworks/4 qt/qml/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 ok READ getOk WRITE setOk NOTIFY okChanged)

public:
inline int getOk() const { return m_ok; }
inline void setOk(int value) {
if (value == m_ok)
return;
m_ok = value;
emit okChanged();
}

signals:
void okChanged();

private:
int m_ok = 42;
};
12 changes: 12 additions & 0 deletions test cases/frameworks/4 qt/qml/QmlMain.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <QGuiApplication>
#include <QQmlApplicationEngine>

int main(int argCount, char* argVector[])
{
QGuiApplication app(argCount, argVector);
QQmlApplicationEngine engine;
engine.addImportPath("qrc:///qt/qml");
engine.addImportPath("qrc:///test");
engine.load("qrc:///qt/qml/My/Module0/Main.qml");
return app.exec();
}
10 changes: 10 additions & 0 deletions test cases/frameworks/4 qt/qml/QmlSingleton.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
pragma Singleton
import QtQuick

Item {
property alias ok: sub.ok

Internal {
id: sub
}
}
4 changes: 4 additions & 0 deletions test cases/frameworks/4 qt/qml/custom_qmldir
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module My.Module4
prefer :/qt/qml/My/Module4/
BasicAliased 1.0 Basic.qml
Thing 1.0 Thing.qml
5 changes: 5 additions & 0 deletions test cases/frameworks/4 qt/qml/custom_qmldir.qrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<RCC>
<qresource prefix="/qt/qml/My/Module4">
<file alias="qmldir">custom_qmldir</file>
</qresource>
</RCC>
63 changes: 63 additions & 0 deletions test cases/frameworks/4 qt/qml/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
qmlmodule1 = qtmodule.qml_module(
qt + 'qmlmodule1',
'My.Module1',
'1.0',
qml_sources: files('Basic.qml', 'subdir/Thing.qml'),
qml_singletons: files('QmlSingleton.qml'),
qml_internals: files('Internal.qml'),
moc_headers: files('QmlCppExposed.hpp', 'QmlCppOtherExposed.hpp'),
designer_supported: true,
dependencies: [qtdep],
install: true
)

#with a different resource prefix
qmlmodule2 = qtmodule.qml_module(
qt + 'qmlmodule2',
'My.Module2',
'1.0',
qml_sources: files('Basic.qml', 'subdir/Thing.qml'),
resources_prefix: '/test',
dependencies: [qtdep],
)

#build without cachegen
qmlmodule3 = qtmodule.qml_module(
qt + 'qmlmodule3',
'My.Module3',
'1.10',
qml_sources: files('Basic.qml', 'subdir/Thing.qml'),
cachegen: false,
dependencies: [qtdep],
)

#build without cachegen
qmlmodule4 = qtmodule.qml_module(
qt + 'qmlmodule4',
'My.Module4',
'1.10',
qml_sources: files('Basic.qml', 'subdir/Thing.qml'),
generate_qmldir: false,
dependencies: [qtdep],
)
qmlmodule4_res = qtmodule.compile_resources(
name : qt + 'qmlmodule4_resource',
sources : files(['custom_qmldir.qrc']),
method : get_option('method')
)

#qml entry point and qmldir dependecies
qmlmodule0 = qtmodule.qml_module(
'qmlmodule0',
'My.Module0',
'1.0',
qml_sources: files('Main.qml'),
imports: ['QtQuick/2.0', 'My.Module1'],
optional_imports: ['My.Module2/auto'],
dependencies: [qtdep],
)


qmltest = executable(qt + '_qmlmodule',
sources : ['QmlMain.cpp', qmlmodule0, qmlmodule1, qmlmodule2, qmlmodule3, qmlmodule4, qmlmodule4_res],
dependencies : qtdep)
5 changes: 5 additions & 0 deletions test cases/frameworks/4 qt/qml/subdir/Thing.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import QtQuick 2.0

Item {
property int ok: 2
}
Loading