我创建了对话框并尝试添加一些别名来更改它的标题和文本:
import QtQuick 2.0
import Ubuntu.Components 0.1
import Ubuntu.Components.Popups 0.1
Item {
signal confirmed;
signal canceled;
property alias title: dialog.title
property alias text: dialog.text
signal show(variant caller);
Component {
id: dialogComponent
Dialog {
id: dialog
title: "Exit Game"
text: "Are you sure that you want to exit?"
Button {
text: "cancel"
onClicked:
{
canceled();
PopupUtils.close(dialog);
}
}
Button {
text: "confirm"
color: "orange"
onClicked:
{
confirmed();
PopupUtils.close(dialog);
}
}
}
}
onShow:
{
PopupUtils.open(dialogComponent, caller)
}
}
但我有问题:
qrc:/ConfirmationDialog.qml:8:23: Invalid alias reference. Unable to find id "dialog"
那么,如何创建这个别名呢?为什么项目看不到它?更改此属性的最佳方法是什么?
此致,
缺口
最佳答案
Dialog 对象在您实例化它之前将不可用,因为它位于组件内部。
如果它不在组件中,您可以引用它的 id。
关于qt - QML:子属性的别名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15953151/