Skip to content

Commit

Permalink
feat: add qml demo
Browse files Browse the repository at this point in the history
  • Loading branch information
tootal committed Jan 16, 2024
1 parent 6952929 commit e79cc16
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ set(CMAKE_PROJECT_LICENSE "${PROJECT_LICENSE}")
add_subdirectory(pivoter)
#add_subdirectory(core)
add_subdirectory(src)
add_subdirectory(qmldemo)
39 changes: 39 additions & 0 deletions qmldemo/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
cmake_minimum_required(VERSION 3.16)

project(demoForQmllsWhatsNew66 VERSION 0.1 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(Qt6 6.4 REQUIRED COMPONENTS Quick)

qt_standard_project_setup()

add_subdirectory(MyModule)

qt_add_executable(appdemoForQmllsWhatsNew66
main.cpp
)

qt_add_qml_module(appdemoForQmllsWhatsNew66
URI demoForQmllsWhatsNew66
QML_FILES Main.qml
RESOURCE_PREFIX /
)

set_target_properties(appdemoForQmllsWhatsNew66 PROPERTIES
MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
MACOSX_BUNDLE TRUE
WIN32_EXECUTABLE TRUE
)

target_link_libraries(appdemoForQmllsWhatsNew66
PRIVATE Qt6::Quick myModule
)

install(TARGETS appdemoForQmllsWhatsNew66
BUNDLE DESTINATION .
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
51 changes: 51 additions & 0 deletions qmldemo/Main.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import QtQuick
import QtQuick.Window
import MyModule

Window {
width: 640
height: 480
visible: true
title: qsTr("Hello World")

MyComponent {
}
component UnknownComponent: Item {
}
UnknownComponent {
}

Item {
id: myItem

property int i
}
property int i
property int childI: myItem.i

function getI() {
f(1, 2, 3);
return myItem.i;
}

function f(a, b, c) {
if (a) {
b = a + b;
} else {
a = a + myItem.i;
}
let sum = 0;
for (i = a; i < b; i = i + c) {
while (a) {
sum = sum + b - c + a * i;
{
let i = 32 // not a definition nor usage of i
i = 44 // neither
}
}
}
console.log(sum);
}

property UnknownComponent myComponent
}
6 changes: 6 additions & 0 deletions qmldemo/MyModule/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

qt_add_qml_module(myModule
URI MyModule
QML_FILES MyComponent.qml
RESOURCE_PREFIX /
)
5 changes: 5 additions & 0 deletions qmldemo/MyModule/MyComponent.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import QtQuick 2.15

Item {
property string data: "Hello World!"
}
17 changes: 17 additions & 0 deletions qmldemo/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <QGuiApplication>
#include <QQmlApplicationEngine>


int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);

QQmlApplicationEngine engine;
const QUrl url(u"qrc:/demoForQmllsWhatsNew66/Main.qml"_qs);
QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed,
&app, []() { QCoreApplication::exit(-1); },
Qt::QueuedConnection);
engine.load(url);

return app.exec();
}

0 comments on commit e79cc16

Please sign in to comment.