Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Contributor
chanzdevilz
Posts: 16
Registered: ‎06-06-2011
My Device: 8520

How to pass own object from qml to other qml

Hi,

 

i have some trouble when want to passing object from 1 qml to other qml.

 

sample code :

//do some import

public A : public QObject {

Q_OBJECT

Q_PROPERTY(int value READ value);

    public :

          A();

          ~A();

 

          int value()

          void setValue(int value);

 

    private :

        int value;

}

// then i register this object to main.cpp

qmlRegisterType<A>("model", 1, 0, "A");

 

then X.qml

import model 1.0

import api 1.0

 

NavigationPane{
             id: nav
             Page{
                          Button:{
                                       onclick:{
                                                    nav.push(page2);
                                       }
                          }
                          onCreationComplete : {
                                       myApi.call();
                          }
                          attachedObject: [
                                       Api{
                                                    id : myApi
                                                    onComplete{
                                                                 z.a = a
                                                    }
                                       },
                                       Test{
                                                    id = page2;
                                       }
                          ]
             }
}

 

//Test.qml

import model 1.0

Page{
             property A a
             Label{
                          text : a.getValue();
             }
}

 

i already tried like this, but it didnt work, and tried using Q_PROPERTY at object A still not work. Could you help me please ?

Developer
strobejb
Posts: 282
Registered: ‎10-15-2012
My Device: bb10 developer

Re: How to pass own object from qml to other qml

Use:

Label {
text: a.value
}

Because its a Q_PROPERTY and not a Q_INVOKABLE you don't need write it as a function call

You also haven't defined the property 'z' anywhere so I'm not sure where that reference is coming from

Contributor
chanzdevilz
Posts: 16
Registered: ‎06-06-2011
My Device: 8520

Re: How to pass own object from qml to other qml

i tried it already, but it still not work. 

Developer
dridk
Posts: 91
Registered: ‎09-25-2012
My Device: bb10 alpha

Re: How to pass own object from qml to other qml

Page{
             Label{
                          text : a.value
             }

 

attachedObject : [

A {

id:a

}

]

}

a lover of Qt
Developer
dridk
Posts: 91
Registered: ‎09-25-2012
My Device: bb10 alpha

Re: How to pass own object from qml to other qml

About property, I m not sure property CustomType works. You should set : property QObject instead
a lover of Qt
Contributor
chanzdevilz
Posts: 16
Registered: ‎06-06-2011
My Device: 8520

Re: How to pass own object from qml to other qml

i have tried it too. instead using QObject, i using property variant a. still not work.

 

when look on slog2info, i got "TypeError: Result of expression 'A' [undefined] is not an object." that happen when 

Api{

       id : myApi
       onComplete{

              console.log(a.getValue()); << happen at here
              z.a = a 
       }
},

 

 

Developer
dridk
Posts: 91
Registered: ‎09-25-2012
My Device: bb10 alpha

Re: How to pass own object from qml to other qml

GetValue should be Q_INVOKABLE 

a lover of Qt
Contributor
chanzdevilz
Posts: 16
Registered: ‎06-06-2011
My Device: 8520

Re: How to pass own object from qml to other qml

already implement it, still not work. could you give me some example or reference for me so i could check my code from it ?

Developer
nemory
Posts: 217
Registered: ‎05-21-2012
My Device: BlackBerry RED Z10

Re: How to pass own object from qml to other qml

try attaching an object in the Page object like

 

1st QML:

 

page.object = passedObject

 

2nd QML:

 

property variant object