Singleton Context Issues
-
Hi everyone, let start with some simplified code:
ScreenManager.qml:
@pragma Singleton
import QtQuick 2.3Item {
function createScreen(fileName, parentItem, obj){ var newScreen = Qt.createComponent(fileName); newScreen.createObject(parentItem, obj); }
}
@Main.qml:
@ Component.onCompleted: {
ScreenManager.createScreen("AnyScreen.qml", root, {"source": "qrc:/images/blabla.png"})
}@Even though I pass a root reference to the singleton function, it doesnt consider my newly created object "AnyScreen.qml" as a child of my root.
It seems like because the creation context is within the singleton, I just get a blank screen instead of what I had before. Anyone know how I could solve this problem ?
-
I just found the problem:
@var newScreen = Qt.createComponent("qrc:/" + fileName);@
If i dont prefix with qrc:/ it will try to load the file from qrc:/singletonfolder/
Good news is that everything is working !!!