读书人

qml 自定义信号解决方法

发布时间: 2012-09-15 19:09:29 作者: rapoo

qml 自定义信号
诸位老师好。我在qml 定义一个信号,调用的时候,却出现如下的错
file:///d:/qmlDemo/first.qml:31: ReferenceError: Can't find variable :buttonClick

first.qml 代码如下:

JScript code
import QtQuick 1.0Rectangle {    width: 400    height: 200    color: "lightblue"    id:aa    Text{        id:bb        anchors.horizontalCenter: parent.horizontalCenter        anchors.verticalCenter: parent.verticalCenter        wrapMode: Text.WordWrap        font.pixelSize: 48        font.italic: true        text:"Press me"        signal buttonClick()        onButtonClick: {            if(mouse.button==Qt.RightButton){                parent.color="blue"            }else {                parent.color="red"            }        }        MouseArea {            anchors.fill: parent            acceptedButtons: Qt.LeftButton|Qt.RightButton            onClicked: buttonClick()        }    }    TextInput {        id:input        x:50;y:150        width: 100        text:"<html><b>Qt Quick</b></html>"    }    Image {        width: 50        height:50        source:"C:/Users/Public/Pictures/Sample Pictures/Chrysanthemum.jpg"    }}



请诸位老师看看,问题在哪?





[解决办法]
应该写成
MouseArea {
anchors.fill: parent
acceptedButtons: Qt.LeftButton|Qt.RightButton
onClicked: bb.buttonClick()
}

读书人网 >QT开发

热点推荐