qt:按钮的无效属性名称'x'(M16)

Hor*_*Kol 6 qt qml

我在QtCreator 3.3.1中使用Qt 5.4.1

我已将QtQuick.Controls 1.2导入我的QML并添加了一系列按钮:

Rectangle {
    id: buttonBar
    x: 480
    y: 0
    width: 320
    height: 80
    Button {
        x: 0
        y: 0

        width: 80
        height: 60

        text: "Songs"
    }

    Button {
        x: 80
        y: 0

        width: 80
        height: 60

        text: "Artists"
    }

    Button {
        x: 160
        y: 0

        width: 80
        height: 60

        text: "Albums"
    }

    Button {
        x: 240
        y: 0

        width: 80
        height: 60

        text: "Back"
    }
}
Run Code Online (Sandbox Code Playgroud)

当我运行程序时它们都可以正常运行,但每次QtCreator打开qml文件时它都会跳转到设计模式并收到警告:

invalid property name 'x' (M16) 
Run Code Online (Sandbox Code Playgroud)

当我在编辑模式下查看文件时,我使用x,y,宽度和高度的行都加下划线.

但文档说这些是我按钮的有效属性 - http://doc.qt.io/qt-5/qml-qtquick-controls-button-members.html

如何停止/解决此错误消息?

小智 8

尝试在 qml 中的所有其他导入之前添加导入 QtQuick.Window 2.2。

  • 对我来说,最重要的是“import QtQml.Models 2.2”来解决这个问题。进口的顺序在这里很重要。 (6认同)

Mee*_*fte 6

这是为使用Qt Creator的控件生成的类型信息中的错误.

要禁止此错误,请添加注释:

Button {
    // @disable-check M16
    x: 80
    y: 0
}
Run Code Online (Sandbox Code Playgroud)


use*_*291 5

在解决任何其他导入和问题之前,我将这些导入移至顶部:

import QtQml.Models 2.2
import QtQml 2.2
Run Code Online (Sandbox Code Playgroud)