标题:qml无法给onCurrentIndexChanged设置别名吗
作者:fghfghfgh
日期:2014-10-23 16:59
内容:
我把ComboBox 写到一个qml文件里,然后在main.qml里面引入
但是 在main里 无法调用qml的onCurrentIndexChanged方法,我尝试个onCurrentIndexChanged设置别名,但是不行啊
可是 给model设置了别名就可以啊
//LabelComboBox.qml
import QtQuick 2.2
import QtQuick.Controls 1.1
Rectangle
{
property alias text:label1.text
property alias model:comboBox1.model
property alias onCurrentIndexChanged:comboBox1.onCurrentIndexChanged
Row {
x: 0
y: 0
spacing: 5
Label {
id: label1
x: 0
y: 4
text: qsTr("Label")
}
ComboBox {
id: comboBox1
width: 130
model: []
onCurrentIndexChanged: console.debug("111")
}
}
}
上面是我的组件代码。无法给onCurrentIndexChanged设置property alias ,大家知道怎么处理吗
#1 [dss020466 10-23 17:23]
首先理解onCurrentIndexChanged这个slot的意思
把属性CurrentIndex定义别名,应该能满足你的需求
#2 [彩阳 10-23 19:37]
楼上做法是对的。
#3 回 dss020466 的帖子 [fghfghfgh 10-24 01:05]
dss020466:首先理解onCurrentIndexChanged这个slot的意思
把属性CurrentIndex定义别名,应该能满足你的需求 (2014-10-23 17:23)
谢谢指点 非常的感谢啊
#4 回 dss020466 的帖子 [fghfghfgh 10-24 01:06]
dss020466:首先理解onCurrentIndexChanged这个slot的意思
把属性CurrentIndex定义别名,应该能满足你的需求 (2014-10-23 17:23)
qml里 只能给属性定义别名不能给信号定义别名吗
#5 [foruok 10-27 10:22]
onXXXChanged是槽,不是信号,不能定义别名。你可以定义一个函数,连接到信号上,也可以在别处调用。