Unsolved Using a singleton without importing it?
-
Hi all,
I want to create a QML singleton with some properties in it (for example some colors to reuse). I'd like that singleton to be usable both when launching my QML application with
qmlscene
and from C++ (through aQApplication
andQQmlApplicationEngine
).The only way I've found was to create a
qmldir
beside myMain.qml
andMySingleton.qml
withsingleton MySingleton 0.1 MySingleton.qml
in it and importing it usingimport "."
inMain.qml
.Is there a way to prevent having to
import "."
wherever I want to use my singleton? I find that import statement confusing as it's not explicit that I'm importing the current directory to get access to the singleton.Normally, I can create a component, say
MyComponent
and save it toMyComponent.qml
. I can then automatically use this component in other qml files through its filename (without extension). Why can't I do this with the singleton?Thanks!
-
I believe the import "." requirement is a bug that's in the bug database.
-
Just for completeness, the bug is this one: https://bugreports.qt.io/browse/QTBUG-34418