wileni
wileni

Reputation: 35

Use QML object from another QML file

Let's say I have the following files:

main.py

app = QGuiApplication(sys.argv)
engine = QQmlApplicationEngine()
engine.quit.connect(app.quit)
engine.load("qml/mainMenu.qml")
sys.exit(app.exec())

main.qml

ApplicationWindow{
    width: 1200
    height: 800
    ...

    CustomObject{...}

customobject.qml

CustomObject{...}

Now as you can see I want to use CustomObject in main.qml. I couldn't find out how to import (or whatever I have to do) both files so I can do that.

Upvotes: 0

Views: 2011

Answers (1)

JarMan
JarMan

Reputation: 8277

If main.qml is in the same directory as CustomObject, then you don't need to import anything at all. If it's not working, it is because you need to rename customobject.qml to be CustomObject.qml. See the docs. At least the first letter must be upper-case, and the object's name becomes the same as the filename. (This can actually be overridden in a qmldir file though).

Upvotes: 1

Related Questions