Skip to content

Commit 5372a4d

Browse files
committed
Add QmlLoader
1 parent b366856 commit 5372a4d

File tree

9 files changed

+195
-0
lines changed

9 files changed

+195
-0
lines changed

QmlLoader/Page1.qml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import QtQuick 2.7
2+
import QtQuick.Window 2.0
3+
import QtQuick.Controls 2.0
4+
5+
Window{
6+
width: 400
7+
height: 300
8+
visible: true
9+
flags: Qt.Window | Qt.WindowStaysOnTopHint
10+
11+
Text{
12+
anchors.top: parent.top
13+
anchors.topMargin: 4
14+
anchors.horizontalCenter: parent.horizontalCenter
15+
text: qsTr("主页一")
16+
}
17+
18+
Button{
19+
height: 32
20+
width: 60
21+
anchors.centerIn: parent
22+
text: qsTr("下一页")
23+
onClicked: changePage();
24+
}
25+
26+
Button{
27+
height: 32
28+
width: 32
29+
text: "X"
30+
anchors.right: parent.right
31+
anchors.rightMargin: 4
32+
anchors.top: parent.top
33+
anchors.topMargin: 4
34+
onClicked: {
35+
Qt.quit()
36+
}
37+
}
38+
39+
Loader{
40+
id: pageLoader
41+
}
42+
43+
function changePage(){
44+
pageLoader.source = "Page2.qml"
45+
close();
46+
}
47+
}

QmlLoader/Page2.qml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import QtQuick 2.7
2+
import QtQuick.Window 2.0
3+
import QtQuick.Controls 2.0
4+
5+
Window{
6+
width: 400
7+
height: 300
8+
visible: true
9+
flags: Qt.Window | Qt.WindowStaysOnTopHint
10+
11+
Text{
12+
anchors.top: parent.top
13+
anchors.topMargin: 4
14+
anchors.horizontalCenter: parent.horizontalCenter
15+
text: qsTr("主页二")
16+
}
17+
18+
Button{
19+
height: 32
20+
width: 60
21+
anchors.centerIn: parent
22+
text: qsTr("下一页")
23+
onClicked: changePage();
24+
}
25+
26+
Button{
27+
height: 32
28+
width: 32
29+
text: "X"
30+
anchors.right: parent.right
31+
anchors.rightMargin: 4
32+
anchors.top: parent.top
33+
anchors.topMargin: 4
34+
onClicked: {
35+
Qt.quit()
36+
}
37+
}
38+
39+
Loader{
40+
id: pageLoader
41+
}
42+
43+
function changePage(){
44+
pageLoader.source = "main.qml"
45+
close();
46+
}
47+
}

QmlLoader/QmlLoader.pro

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#-------------------------------------------------
2+
#
3+
# Copyright (C) 2003-2103 CamelSoft Corporation
4+
#
5+
#-------------------------------------------------
6+
7+
QT += qml quick
8+
9+
CONFIG += c++11
10+
11+
SOURCES += main.cpp
12+
13+
RESOURCES += qml.qrc

QmlLoader/main.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*!
2+
*@file main.cpp
3+
*@brief 程序主文件
4+
*@version 1.0
5+
*@section LICENSE Copyright (C) 2003-2103 CamelSoft Corporation
6+
*@author zhengtianzuo
7+
*/
8+
#include <QGuiApplication>
9+
#include <QQmlApplicationEngine>
10+
11+
int main(int argc, char *argv[])
12+
{
13+
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
14+
QGuiApplication app(argc, argv);
15+
16+
QQmlApplicationEngine engine;
17+
engine.load(QUrl(QLatin1String("qrc:/main.qml")));
18+
19+
return app.exec();
20+
}

QmlLoader/main.qml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*!
2+
*@file main.qml
3+
*@brief 主文件
4+
*@version 1.0
5+
*@section LICENSE Copyright (C) 2003-2103 CamelSoft Corporation
6+
*@author zhengtianzuo
7+
*/
8+
import QtQuick 2.7
9+
import QtQuick.Window 2.0
10+
import QtQuick.Controls 2.0
11+
12+
Window{
13+
width: 400
14+
height: 300
15+
visible: true
16+
flags: Qt.Window | Qt.WindowStaysOnTopHint
17+
title: qsTr("QmlLoader")
18+
19+
Text{
20+
anchors.top: parent.top
21+
anchors.topMargin: 4
22+
anchors.horizontalCenter: parent.horizontalCenter
23+
text: qsTr("主页面")
24+
}
25+
26+
Button{
27+
height: 32
28+
width: 60
29+
anchors.centerIn: parent
30+
text: qsTr("下一页")
31+
onClicked: changePage();
32+
}
33+
34+
Button{
35+
height: 32
36+
width: 32
37+
text: "X"
38+
anchors.right: parent.right
39+
anchors.rightMargin: 4
40+
anchors.top: parent.top
41+
anchors.topMargin: 4
42+
onClicked: {
43+
Qt.quit()
44+
}
45+
}
46+
47+
Loader{
48+
id: pageLoader
49+
}
50+
51+
function changePage(){
52+
pageLoader.source = "Page1.qml"
53+
close();
54+
}
55+
}

QmlLoader/qml.qrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<RCC>
2+
<qresource prefix="/">
3+
<file>main.qml</file>
4+
<file>Page1.qml</file>
5+
<file>Page2.qml</file>
6+
</qresource>
7+
</RCC>

QmlLoader/show.gif

60 KB
Loading

QtQuickExamples.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ SUBDIRS += QmlWinExtras
3535
SUBDIRS += QmlCalendar
3636
SUBDIRS += QmlCanvasText
3737
SUBDIRS += QmlKey
38+
SUBDIRS += QmlLoader

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,8 @@ QmlKey: Qml全局按键
157157

158158
![](https://github.com/zhengtianzuo/QtQuickExamples/blob/master/QmlKey/show.gif?raw=true)
159159

160+
161+
QmlLoader: QmlLoader
162+
163+
![](https://github.com/zhengtianzuo/QtQuickExamples/blob/master/QmlLoader/show.gif?raw=true)
164+

0 commit comments

Comments
 (0)