Skip to content

Commit e79cc16

Browse files
committed
feat: add qml demo
1 parent 6952929 commit e79cc16

File tree

6 files changed

+119
-0
lines changed

6 files changed

+119
-0
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ set(CMAKE_PROJECT_LICENSE "${PROJECT_LICENSE}")
1212
add_subdirectory(pivoter)
1313
#add_subdirectory(core)
1414
add_subdirectory(src)
15+
add_subdirectory(qmldemo)

qmldemo/CMakeLists.txt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
cmake_minimum_required(VERSION 3.16)
2+
3+
project(demoForQmllsWhatsNew66 VERSION 0.1 LANGUAGES CXX)
4+
5+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
6+
7+
find_package(Qt6 6.4 REQUIRED COMPONENTS Quick)
8+
9+
qt_standard_project_setup()
10+
11+
add_subdirectory(MyModule)
12+
13+
qt_add_executable(appdemoForQmllsWhatsNew66
14+
main.cpp
15+
)
16+
17+
qt_add_qml_module(appdemoForQmllsWhatsNew66
18+
URI demoForQmllsWhatsNew66
19+
QML_FILES Main.qml
20+
RESOURCE_PREFIX /
21+
)
22+
23+
set_target_properties(appdemoForQmllsWhatsNew66 PROPERTIES
24+
MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
25+
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
26+
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
27+
MACOSX_BUNDLE TRUE
28+
WIN32_EXECUTABLE TRUE
29+
)
30+
31+
target_link_libraries(appdemoForQmllsWhatsNew66
32+
PRIVATE Qt6::Quick myModule
33+
)
34+
35+
install(TARGETS appdemoForQmllsWhatsNew66
36+
BUNDLE DESTINATION .
37+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
38+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
39+
)

qmldemo/Main.qml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import QtQuick
2+
import QtQuick.Window
3+
import MyModule
4+
5+
Window {
6+
width: 640
7+
height: 480
8+
visible: true
9+
title: qsTr("Hello World")
10+
11+
MyComponent {
12+
}
13+
component UnknownComponent: Item {
14+
}
15+
UnknownComponent {
16+
}
17+
18+
Item {
19+
id: myItem
20+
21+
property int i
22+
}
23+
property int i
24+
property int childI: myItem.i
25+
26+
function getI() {
27+
f(1, 2, 3);
28+
return myItem.i;
29+
}
30+
31+
function f(a, b, c) {
32+
if (a) {
33+
b = a + b;
34+
} else {
35+
a = a + myItem.i;
36+
}
37+
let sum = 0;
38+
for (i = a; i < b; i = i + c) {
39+
while (a) {
40+
sum = sum + b - c + a * i;
41+
{
42+
let i = 32 // not a definition nor usage of i
43+
i = 44 // neither
44+
}
45+
}
46+
}
47+
console.log(sum);
48+
}
49+
50+
property UnknownComponent myComponent
51+
}

qmldemo/MyModule/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
qt_add_qml_module(myModule
3+
URI MyModule
4+
QML_FILES MyComponent.qml
5+
RESOURCE_PREFIX /
6+
)

qmldemo/MyModule/MyComponent.qml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import QtQuick 2.15
2+
3+
Item {
4+
property string data: "Hello World!"
5+
}

qmldemo/main.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <QGuiApplication>
2+
#include <QQmlApplicationEngine>
3+
4+
5+
int main(int argc, char *argv[])
6+
{
7+
QGuiApplication app(argc, argv);
8+
9+
QQmlApplicationEngine engine;
10+
const QUrl url(u"qrc:/demoForQmllsWhatsNew66/Main.qml"_qs);
11+
QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed,
12+
&app, []() { QCoreApplication::exit(-1); },
13+
Qt::QueuedConnection);
14+
engine.load(url);
15+
16+
return app.exec();
17+
}

0 commit comments

Comments
 (0)