-1
我在QML中更改視圖/文件時遇到問題。在qrc文件中,我有main.qml和second.qml。在main.cpp中我的代碼開始我的應用程序:從Qt(main.cpp)QML中查看
QQuickView view;
view.setSource(QUrl(("qrc:///main.qml")));
view.show();
在main.qml是按鈕,應該改變以second.qml,但我不知道用什麼方式做到這一點。我讀過關於qml的內容,但是在任何地方我找到了這些示例
的main.qml:
Item {
id: screen; width: 320; height: 480;
signal exitApp()
signal qmlSignal(string addressIP, int portTCP)
Rectangle {
id: background
anchors.fill: parent; color: "#ffffff";
anchors.rightMargin: 0
anchors.bottomMargin: 0
anchors.leftMargin: 0
anchors.topMargin: 0
Button {
id: loginBtn
text: qsTr("RUN")
anchors.right: parent.right
anchors.rightMargin: 100
anchors.left: parent.left
anchors.leftMargin: 100
anchors.bottom: parent.bottom
anchors.bottomMargin: 170
anchors.top: tcpRow.bottom
anchors.topMargin: 10
onClicked: qmlSignal(addressIPTextField.text, parseInt(portTCPTextField.text))
}
}
Row {
id: tcpRow
x: 8
width: 309
height: 100
anchors.top: ipRow.bottom
anchors.topMargin: 10
anchors.horizontalCenter: parent.horizontalCenter
Label {
id: portTCPLabel
height: 20
text: qsTr("Port TCP")
anchors.left: parent.left
anchors.leftMargin: 10
anchors.right: portTCPTextField.left
anchors.rightMargin: 10
anchors.verticalCenter: parent.verticalCenter
}
}}
感謝您的回覆,但什麼意思'StackView.view'?它是從main.cpp中查看的? – Szymson
正如我在我的回答中提到的那樣,它是'StackView'的附加屬性。請閱讀我鏈接到的文檔。 – Mitch