How to pass properties to a child window



  • Hi,

    I have a dialog that I am showing using QQuickView (PyQt5). Before loading the QML I set a userName property using view.rootContext().SetContextProperty(). In the main form the userName I set is displayed correctly, but when I open a child form (using the QML Window class) and attempt to pass the userName to it then it gets set to the default value instead of the value that I set in SetContextProperty.

    What is going wrong here and how can I fix it?

    Glenn

    @
    Rectangle {
    id: main
    objectName: "main"
    property string userName: "Foo Bar"
    ...
    MouseArea {
    ...
    onClicked: {
    editNameForm.visible = true
    editNameForm.userName = "%1".arg(main.userName)
    // main.userName Is always "Foo Bar" instead of the value set using SetContextProperty()
    console.log("userName: ", main.userName)
    }
    }
    EditName {
    // This is derived from the Window class
    id: editNameForm
    ....
    }
    }
    @


  • Moderators

    Hi,

    What if you don't assign the "Foo Bar" to userName ? Just keep it like this,

    @ property string userName@



  • Look's like the forum lost a few posts.

    [quote author="p3c0" date="1382158485"]Hi,

    What if you don't assign the "Foo Bar" to userName ? Just keep it like this,

    @ property string userName@[/quote]

    If I do that that then it still passes through the initial value of userName, which in this case is "".


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.