• 5049阅读
  • 1回复

[提问]qml Row的parent不是item吗?TypeError: Result of expression 'parent' [null] is not an object. [复制链接]

上一主题 下一主题
离线qiaofangjie
 
只看楼主 倒序阅读 楼主  发表于: 2013-01-17
关键词: 求助
最近学习qml,在qt_quick中文手册上抄了一个例子FileMenu.qml,结果报错,不知道为什么?代码如下
FileMenu.qml:
  1. import Qt 4.7
  2. Row
  3. {
  4.     anchors.centerIn: parent
  5.     spacing: parent.width/6
  6.     Button
  7.     {
  8.         id: loadButton
  9.         buttonColor: "lightgrey"
  10.         label: "Load"
  11.     }
  12.     Button
  13.     {
  14.         id: saveButton
  15.         buttonColor: "grey"
  16.         label: "Save"
  17.     }
  18.     Button
  19.     {
  20.         id: exitButton
  21.         buttonColor: "darkgrey"
  22.         label: "Exit"
  23.         onButtonClick: Qt.quit()
  24.     }
  25. }
Button.qml:
  1. import Qt 4.7
  2. Rectangle
  3. {
  4.     border.width: 3
  5.     id:simplebutton
  6.     color: buttonMouseArea.pressed ? Qt.darker(buttonColor, 1.5) : buttonColor
  7.     width: 150; height: 75
  8. //    radius: 10
  9.     property color buttonColor: "lightblue"
  10.     property color onHoverColor: "red"
  11.     property color borderColor: "white"
  12.     property string label: "button label"
  13.     signal buttonClick()
  14.     onButtonClick:
  15.     {
  16.         console.log(buttonLabel.text + " clicked")
  17.     }
  18.     Text
  19.     {
  20.         id: buttonLabel
  21.         anchors.centerIn: parent
  22.         text: label
  23.     }
  24.     MouseArea
  25.     {
  26.         id: buttonMouseArea
  27.         anchors.fill: parent
  28.         onClicked: buttonClick()
  29.         hoverEnabled: true
  30.         onEntered: parent.border.color = onHoverColor
  31.         onExited: parent.border.color = borderColor
  32.     }
  33.     
  34. }





离线qiaofangjie
只看该作者 1楼 发表于: 2013-01-17
Re:qml Row的parent不是item吗?TypeError: Result of expression 'parent' [null] is not an &nbs
执行qmlviewer FileMenu.qml 后,报错:FileMenu.qml:6: TypeError: Result of expression 'parent' [null] is not an object.
请大家指教
快速回复
限100 字节
 
上一个 下一个