Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Bug or ... ? Custom element's attribute gets superfluously re-initialized.
Forum Updated to NodeBB v4.3 + New Features

Bug or ... ? Custom element's attribute gets superfluously re-initialized.

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qml binding bug
1 Posts 1 Posters 139 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Christian Parpart
    wrote on last edited by Christian Parpart
    #1

    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 to myGlobal.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).

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved