-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