1
votes

I'm trying to create a custom QML object. I started simple, by making a qml file called rect.qml:

import QtQuick 2.2
Rectangle 
{ }

In the same directory, I wanted to use my rect object in a seperate qml file, called window.qml:

import QtQuick 2.2
Item {
  id: mainWindow
  rect
  { }
}

Very high caliber stuff, I know. Anyway, when I try to run my application, I get the following error:

qrc:/qml/window.qml:3:13: Cannot assign to non-existent property "rect"

So I checked my QRC file, and it goes as such:

<RCC>
    <qresource prefix="/qml">
        <file>window.qml</file>
        <file>rect.qml</file>
    </qresource>
</RCC>

According to the documentation (http://doc.qt.io/qt-5/qtqml-documents-definetypes.html) this application isn't very useful as it's so bare bones, (simplified for my question,) but there shouldn't be an error.

Any help would be very appreciated!

2
Have you tried renaming it to Rect.qml and consequently in window.qml? - bipll
You guys nailed it! Thank you for your time and feedback! - Eagle13559

2 Answers

2
votes

You must rename the file to Rect.qml and call it Rect{}

3
votes

QML imposes some limitations on how you can name things, QML documents or exposed C++ enums keys must begin with capital letters, and properties or ids must not begin with a capital letter. I don't recall this being documented in one single, convenient article as it should. Most are documented, but it is spread all over the place.