qt: invalid property name 'x' (M16) for button

17,671

Solution 1

It's a bug in the type info that is generated for controls for use of Qt Creator.

To suppress this error, add comment:

Button {
    // @disable-check M16
    x: 80
    y: 0
}

Solution 2

Try to add import QtQuick.Window 2.2 before all other imports in qml.

Solution 3

I moved these imports to the top, before any other import and problem got resovled:

import QtQml.Models 2.2
import QtQml 2.2
Share:
17,671

Related videos on Youtube

HorusKol
Author by

HorusKol

Software developer.

Updated on June 14, 2022

Comments

  • HorusKol
    HorusKol about 2 years

    I'm using Qt 5.4.1 in QtCreator 3.3.1

    I've imported QtQuick.Controls 1.2 into my QML and added a series of buttons:

    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"
        }
    }
    

    They all render fine when I run the program, but everytime that QtCreator opens the qml file it jumps into design mode and I get the warning:

    invalid property name 'x' (M16) 
    

    and the lines where I use x, y, width and height are all underlined when I view the file in edit mode.

    But the documentation says these are valid properties for my buttons - http://doc.qt.io/qt-5/qml-qtquick-controls-button-members.html

    How do I stop/resolve this error message?

  • Nostalg.io
    Nostalg.io over 9 years
    Thank you so much. This suppresses the error, but still doesn't allow the button to be positioned or edited using the handy Designer mode. Any tricks to get a button working in Designer mode?
  • Meefte
    Meefte over 9 years
    @halfnibble Only change your Qt to version without bug. Qt 5.4.0 and QtCreator 3.3.0 is fine.
  • user3417815
    user3417815 over 5 years
    This one is really useful
  • dreua
    dreua about 5 years
    For me it's import QtQml.Models 2.2 on top to fix this. The order of imports matters here.
  • Saeed Masoomi
    Saeed Masoomi over 3 years
    We can fix the problem here with the solution but the problem is that the autocomplete feature is not working well.
  • Saeed Masoomi
    Saeed Masoomi over 3 years
    Thanks for the answer, It solved my issue but do you know why the problem appears and why these imports will solve it?