add code
This commit is contained in:
42
1DemoApp/CMakeLists.txt
Normal file
42
1DemoApp/CMakeLists.txt
Normal file
@@ -0,0 +1,42 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(1DemoApp VERSION 0.1 LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
find_package(Qt6 REQUIRED COMPONENTS Quick)
|
||||
|
||||
qt_standard_project_setup(REQUIRES 6.5)
|
||||
|
||||
qt_add_executable(app1DemoApp
|
||||
main.cpp
|
||||
)
|
||||
|
||||
qt_add_qml_module(app1DemoApp
|
||||
URI 1DemoApp
|
||||
VERSION 1.0
|
||||
QML_FILES
|
||||
Main.qml
|
||||
)
|
||||
|
||||
# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
|
||||
# If you are developing for iOS or macOS you should consider setting an
|
||||
# explicit, fixed bundle identifier manually though.
|
||||
set_target_properties(app1DemoApp PROPERTIES
|
||||
# MACOSX_BUNDLE_GUI_IDENTIFIER com.example.app1DemoApp
|
||||
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(app1DemoApp
|
||||
PRIVATE Qt6::Quick
|
||||
)
|
||||
|
||||
include(GNUInstallDirs)
|
||||
install(TARGETS app1DemoApp
|
||||
BUNDLE DESTINATION .
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
)
|
||||
72
1DemoApp/Main.qml
Normal file
72
1DemoApp/Main.qml
Normal file
@@ -0,0 +1,72 @@
|
||||
import QtQuick
|
||||
|
||||
Window {
|
||||
id: rootId
|
||||
width: 640
|
||||
height: 480
|
||||
visible: true
|
||||
title: qsTr("Hello World")
|
||||
property string textToShow: "hello"
|
||||
// Text {
|
||||
// text: "Hello World!"
|
||||
// font.family: "Helvetica"
|
||||
// font.pointSize: 24
|
||||
// color: "red"
|
||||
// anchors.centerIn: parent
|
||||
// }
|
||||
Row {
|
||||
id: row1
|
||||
anchors.centerIn: parent
|
||||
spacing: 20
|
||||
Rectangle {
|
||||
id: redRectId
|
||||
width: 100
|
||||
height: 100
|
||||
color: "red"
|
||||
radius: 20
|
||||
Text {
|
||||
id: textId
|
||||
anchors.centerIn: parent
|
||||
text: rootId.textToShow
|
||||
color: "white"
|
||||
font.pointSize: 15
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
onClicked: {
|
||||
console.log(textId.text)
|
||||
textToShow = "clicked"
|
||||
}
|
||||
}
|
||||
}
|
||||
Rectangle {
|
||||
id: blueRectId
|
||||
width: 100
|
||||
height: 100
|
||||
color: "blue"
|
||||
radius: 20
|
||||
}
|
||||
Rectangle {
|
||||
id: greenRectId
|
||||
width: 100
|
||||
height: 100
|
||||
// radius:
|
||||
color: "green"
|
||||
radius: 20
|
||||
}
|
||||
Rectangle {
|
||||
width: 100
|
||||
height: 100
|
||||
color: "dodgerblue"
|
||||
radius: 100
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
onClicked: {
|
||||
console.log("Clicked on dodgerblue circle")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
18
1DemoApp/main.cpp
Normal file
18
1DemoApp/main.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#include <QGuiApplication>
|
||||
#include <QQmlApplicationEngine>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QGuiApplication app(argc, argv);
|
||||
|
||||
QQmlApplicationEngine engine;
|
||||
QObject::connect(
|
||||
&engine,
|
||||
&QQmlApplicationEngine::objectCreationFailed,
|
||||
&app,
|
||||
[]() { QCoreApplication::exit(-1); },
|
||||
Qt::QueuedConnection);
|
||||
engine.loadFromModule("1DemoApp", "Main");
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
Reference in New Issue
Block a user