Qml文本元素语法错误

时间:2015-03-25 03:22:43

标签: qt syntax-error qml qtquick2

我得到以下内容 -

file:///C:/Qt/5.4/mingw491_32/Design1.qml:9:1: Syntax error 
     Text {

     ^

这是我非常简单的代码但我无法在qmlviewer中运行

import QtQuick 2.0

Rectangle {
    id: page
    width: 500; height: 200
    color: "lightgray"
}

Text {
    id: Text1
    text: "Hello World!"
    y: 30
    anchors.horizontalCenter: page.horizontalCenter
    font.pointSize: 24; font.bold: true
}

2 个答案:

答案 0 :(得分:0)

id s在ID名称的开头不能有大写字母。

Text1更改为text1,它应该有效。

答案 1 :(得分:-2)

我发现我的问题是我忘记让txt {}成为Rectangle的子项,因为只能有一个。

import QtQuick 1.0

Rectangle {
    id: page
    width: 500; height: 200
    color: "lightgray"

    Text {   // Indented
        id: text1
        text: "Hello World!"
        y: 30
        anchors.horizontalCenter: page.horizontalCenter
        font.pointSize: 24; font.bold: true
    }
}