I'm unable to access variables in a separate file.
Down below is part of my code:
// Style.qml
import QtQuick
QtObject {
property int mainWindowWidth: 1024
property int mainWindowHeight: 768
}
// Main.qml
import QtQuick
import QtQuick.Window
Window {
id: root
width: Style.mainWindowWidth
height: Style.mainWindowHeight
minimumWidth: width
minimumHeight: height
maximumWidth: width
maximumHeight: height
visible: true
title: "Sampletext"
}
It compiles fine but when I run it, I get an error saying:
Unable to assign [undefined] to int where the line width: Style.mainWindowWidth is located.
How do I fix this?
You should create an instance of the
Stylecomponent or defineStyleas a singleton component. Definition ofStyleas singleton is as follows:Style.qml
CMakeLists.txt:
Main.qml