qml 默认信号处理程序无法工作
---问题---
我创建一个“TextBtn”组件并在其中添加一个信号“btnClicked”:
TextBtn.qml
import Qt 4.7
Rectangle {
property alias btnText: showStr.text
width:100
height:30
border.color: "black"
border.width: 1
color: "white"
signal btnClicked()
//the default signal handler
onBtnClicked: console.log(btnText+" is clicked.")
MouseArea {
id: btnMouseArea
anchors.fill: parent
onClicked: btnClicked()
}
Text {
id: showStr
anchors.centerIn: parent
color: "black"
}
}
另一个组件“MenuRow”包含三个“TextBtn”,如下所示:
MenuRow.qml
import Qt 4.7
Row {
spacing: 5
TextBtn {
id: testBtn01
btnText: "test01"
}
TextBtn {
id: testBtn02
btnText: "test02"
}
TextBtn {
id: testBtn03
btnText: "test03"
}
}
默认单个处理程序“onBtnClicked”当单击“MenuRow”中的“TextBtn”之一时,应该触发“TextBtn”中的“”,但事实并非如此。这是怎么回事?
相关的qml文档在这里:http://doc。 qt.nokia.com/4.7/gettingstartedqml.html#basic-component-a-button
---开发环境---
OS:Ubuntu 10.04
Qt版本:4.7.0(使用“qt-sdk-linux- x86-opensource-2010.05.1.bin”在默认路径“$HOME/qtsdk-2010.05/”中安装qt sdk)
在运行qml之前,我源了一个文件“qtsetup.sh”来设置相关路径,
$ source qtsetup.sh
qtsetup.sh
QTDIR=$HOME/qtsdk-2010.05/qt/
PATH=$PATH:$QTDIR/bin
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$QTDIR/lib
然后使用“qmlviewer”运行qml 文件。
$ qmlviewer MenuRow.qml
qmlviewer 窗口被触发并显示“MenuRow”。没有错误发生。我用鼠标单击“MenuRow”中的“TextBtn”,但没有任何反应。 (它应该在终端中显示一条消息“text0X is clicked”。)
我使用 qmlviewer 运行其他示例和演示,它们似乎运行良好。我不知道为什么这个例子不能工作。
---Question---
I create a "TextBtn" component and add a signal "btnClicked" in it:
TextBtn.qml
import Qt 4.7
Rectangle {
property alias btnText: showStr.text
width:100
height:30
border.color: "black"
border.width: 1
color: "white"
signal btnClicked()
//the default signal handler
onBtnClicked: console.log(btnText+" is clicked.")
MouseArea {
id: btnMouseArea
anchors.fill: parent
onClicked: btnClicked()
}
Text {
id: showStr
anchors.centerIn: parent
color: "black"
}
}
Another component "MenuRow" contains three "TextBtn"s as follows:
MenuRow.qml
import Qt 4.7
Row {
spacing: 5
TextBtn {
id: testBtn01
btnText: "test01"
}
TextBtn {
id: testBtn02
btnText: "test02"
}
TextBtn {
id: testBtn03
btnText: "test03"
}
}
The default single handler "onBtnClicked" in "TextBtn" should be triggered when one of "TextBtn"s in "MenuRow" is clicked, but it doesn't. What's going on?
The related qml doc is here: http://doc.qt.nokia.com/4.7/gettingstartedqml.html#basic-component-a-button
---Development Environment---
OS: Ubuntu 10.04
Qt Version: 4.7.0(Use "qt-sdk-linux-x86-opensource-2010.05.1.bin" to install qt sdk in the default path "$HOME/qtsdk-2010.05/")
Before running qml, I source a file "qtsetup.sh" to set the related paths,
$ source qtsetup.sh
qtsetup.sh
QTDIR=$HOME/qtsdk-2010.05/qt/
PATH=$PATH:$QTDIR/bin
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$QTDIR/lib
then run qml files with "qmlviewer".
$ qmlviewer MenuRow.qml
A qmlviewer window is triggered and shows the "MenuRow". No error occurs. I use mouse to click "TextBtn" in "MenuRow", but nothing happens. (It should show a message "text0X is clicked" in the terminal.)
I use qmlviewer to run other examples and demos, they seem to work well. I don't know why this example cannot work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题也发生在这里(qmlviewer 4.7.0)。
看起来这是 qmlviewer 中的一个错误,请阅读后续内容 此处< /a>.
如果删除别名 (btnText),信号将起作用。 (但正确的解决方案是更新到4.7.1+)
The problem happens here too (qmlviewer 4.7.0).
Looks like it's a bug in qmlviewer, read the follow-ups here.
If you remove your alias (btnText), the signal will work. (But the proper solution is update to 4.7.1+)