【发布时间】:2025-11-28 12:05:01
【问题描述】:
我必须将一些值从使用组件打开的子 QML 传递到主 QML,并使用它们在主 QML 中执行某些操作。
这是我的两个 QML 文件:
我有这样的mail.qml:
import QtQuick 2.10
import QtQuick.Window 2.10
import QtQuick.Controls 2.3
ApplicationWindow {
id: applicationWindow
property string selected_contact_account_str: String()
/* Contacts */
function createContacts() {
var component = Qt.createComponent("ContactList.qml");
console.log("Component Status:", component.status, component.errorString());
var window = component.createObject(applicationWindow, {"x": 0, "y": 0});
window.showFullScreen();
}
Icon {
id: contacts
anchors.top: parent.top
anchors.topMargin: 60
anchors.left: parent.left
anchors.leftMargin: 20
iconsize: 96
iconsource: "content/contacts_icon.png"
iconname: "Contacts"
fontsize: 14
MouseArea {
anchors.fill: parent
onClicked: createContacts()
}
}
/* End Contacts */
}
还有一个带按钮的 ContactList.qml:
import QtQuick 2.10
import QtQuick.Controls 2.3
import QtQuick.Window 2.2
ApplicationWindow {
id: contactsList
Item {
Item {
id: appContainer
anchors.fill: parent
anchors.centerIn: parent
Button {
id: contact_select
text: qsTr("Select")
onClicked: {
// I want to pass value from here to main.qml
// store in selected_contact_account_str
// So I can use it in mail.qml
}
}
}
}
我该怎么办?
【问题讨论】: