03-02-2013 05:18 PM
I have a context variable cppObject define as usual :
QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);
qml->setContextProperty("cppObject", this);
And it works fine in the main.qml.
Problem is that it doesn't work in the second QML files pagetwo.qml which is created on the fly in main.qml when button is clicked.
Any idea how to access C++ from pagetwo.qml?
Thanks.
Solved! Go to Solution.
03-02-2013 05:26 PM
Hi,
Did you remember to import your custom library in the second Page too?
It's easy to forget.
If you did can you say what you mean by 'doesn't work', what error/warning message are you getting from the slogger?
03-02-2013 05:38 PM
I've made a simple test app to reproduce this, but I see "HELLO FROM C++" on both pages:
main.qml
// Navigation pane project template
import bb.cascades 1.0
NavigationPane {
id: navigationPane
Page {
Container {
Label {
text: injection.testFunc()
}
Button {
text: "Other page"
onClicked: {
// show detail page when the button is clicked
var page = getSecondPage();
navigationPane.push(page);
}
property Page secondPage
function getSecondPage() {
if (! secondPage) {
secondPage = secondPageDefinition.createObject();
}
return secondPage;
}
attachedObjects: [
ComponentDefinition {
id: secondPageDefinition
source: "DetailsPage.qml"
}
]
}
}
}
}
DetailsPage.qml:
// Navigation pane project template
import bb.cascades 1.0
Page {
Container {
Label {
text: injection.testFunc()
}
}
}
TestEmpty3.cpp:
QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(th is);
qml->setContextProperty("injection", this);
...
QString TestEmpty3::testFunc()
{
return "HELLO FROM C++";
}
TestEmpty3.h:
Q_INVOKABLE QString testFunc();
03-02-2013 07:44 PM
03-02-2013 08:32 PM
Hi Zmey, i'm having the same issue and I still have not been able to resolve it. Would you be able to post all the content from your test project, or provide all all of it (zip) somewhere on the web. This issue has been driving me nuts, and after reading soooooo many posts I still haven't been able to figure it out why.
Thanks
03-02-2013 08:53 PM
costaf wrote:
Hi Zmey, i'm having the same issue and I still have not been able to resolve it. Would you be able to post all the content from your test project, or provide all all of it (zip) somewhere on the web. This issue has been driving me nuts, and after reading soooooo many posts I still haven't been able to figure it out why.
Thanks
Is it working from one QML file but not in the second, or not working at all? Can you show me your .hpp ?
03-03-2013 03:30 AM