02-08-2013 03:03 AM
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 ?
02-08-2013 05:22 AM
02-08-2013 05:39 AM
i tried it already, but it still not work.
02-08-2013 06:11 AM
Page{
Label{
text : a.value
}
attachedObject : [
A {
id:a
}
]
}
02-08-2013 06:11 AM
02-08-2013 06:40 AM
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
}
},
02-08-2013 06:47 AM
GetValue should be Q_INVOKABLE
02-08-2013 09:16 AM
already implement it, still not work. could you give me some example or reference for me so i could check my code from it ?
02-08-2013 09:26 AM
try attaching an object in the Page object like
1st QML:
page.object = passedObject
2nd QML:
property variant object