Bug or ... ? Custom element's attribute gets superfluously re-initialized.
-
Hey,
Disclaimer: I am new to QML/QtQuick, i.e. I am in fact porting a QtWidgets app to QML/QtQuick. I am using Qt 5 (e.g. 5.12).
I am having a .qml file containing a Window along with one attribute set via a custom call to some exported data model.
I do really expect to have this function to be only invoked upon instantiation.
But now imagine calling qmlEngine.load("That.qml") more than once, expecting it to create more of these windows.
When creating three windows, I do expect that my custom call tomyGlobal.createDynamicText()
is happening once per qml file instantiation, so in total three times, but it is being invoked 1+2+3=6 times.
Why? Because load(QUrl("That.qml")) will not just load that QML file but also it seems to re-initialize all windows that did exist up until that moment, too, hence 1+2+3=6.ApplicationWindow { id: appWindow visible: true color: "transparent" width: 300 height: 200 Rectangle { id: myRect anchors.fill: parent color: "black" Text { id: myText // This function is to show that I want to attach some content dynamically. // It must be only invoked once per instantiation of this .qml file, but // running this proves it's called way to many times. text: myGlobal.createDynamicText() font.family: "Helvetica" font.pointSize: 24 anchors.centerIn: parent color: "yellow" } } }
As an attempt to get help I was already creating a as minimalist example as possible and put it on Github:
https://github.com/christianparpart/qmlcpptest/
If you do not want to build the project, please just have a look at the screenshot.
I need the ability to create new windows of the same type. If I can't get this working, I feel I just need to stick with QtWidgets until Qt6 is widely supported on even the oldest Linux LTS versions, sadly (someone trying to help me said it's fixed on Qt6, at least he can't repro it on his Qt6, with my example source code, but I need that to work on Qt5).