2

I have a basic code but it's impossible to send a property to an external page

This is my main.qml :

 PageStack {
        id: pageStack
        Component.onCompleted: push(pageMain)
        Page {
            title: i18n.tr("Main page")
            id:pageMain

            Button {
                objectName: "button"
                width: parent.width

                text: i18n.tr("send value")

                onClicked: {
                    var codeValue = "3029330003533";
                    console.log("code = " + codeValue);
                    pageStack.push(Qt.resolvedUrl("qml/view.qml", {code: codeValue}));
                }
            }

        }
    }

And my qml/view.qml page

import QtQuick 2.4
import Ubuntu.Components 1.2

Page {
    title: "View"
    id: pageView
   property string code:"";

    Column {
        spacing: units.gu(1)
        anchors {
            margins: units.gu(2)
            fill: parent
        }

        Label {
            id: label
            objectName: "label"
            text: pageView.code
        }
    }
}

property "barcode" is always empty, where is my mistake ?

2 Answers 2

2

You parens aren't quite right:

pageStack.push(Qt.resolvedUrl("qml/view.qml"), {code: codeValue});
0
1

Try making your property name a string, like this: {'code': codeValue}, otherwise Qml is likely trying to evaluate code as a variable rather than a literal.

1
  • It's change nothing. For test the values I had : onCodeChanged: console.log(pageView.code) ; -- but this method is never called --
    – Nymeria
    Jun 16, 2015 at 20:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .