下面是一个加载QML文件的基本例子如下:
#include <QGuiApplication>
#include <QQuickView>
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQuickView view;
view.setSource(QUrl(QStringLiteral("qrc:/main.qml")));
view.show();
return app.exec();
}
import QtQuick 2.3
import QtQuick.Controls 1.4
Rectangle {
id: rootRect
width: 800
height: 600
color: '#808080'
MouseArea {
anchors.fill: parent
onClicked: {
testText.color = 'red'
}
}
Text {
id: testText
anchors.centerIn: parent
text: qsTr("Helle QML!")
color: 'white'
}
}