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
scottdeagan
Posts: 43
Registered: ‎05-07-2012
My Device: Z10 • Z30 • PlayBook
Accepted Solution

Adding images dynamically - tutorial examples do not work

I'm using the Gold SDK, and am working throught the tutorials. I want to add images dynamically from C++. The tutorial I'm using is here:

 

https://developer.blackberry.com/cascades/documentation/dev/integrating_cpp_qml/ (under the heading "Injecting C++ objects into QML").

 

I copy/pasted the main.cpp, TestApp.hpp and TestApp.cpp into a new project. It compiled and ran on my handset, but when I click the "Add Container" button the application seg faults and terminates.

 

I understand that this is usually caused by a NULL pointer, so I added:

 

this->mRootContainer = new bb::cascades::Container();

 

to the constructor. Now it doesn't seg fault when I press the "Add Container" button, but it still doesn't actually add the container (it doesn't add anything visible).

 

How can I use the concepts outlined in that tutorial to add an image at runtime?

 

 

Contributor
scottdeagan
Posts: 43
Registered: ‎05-07-2012
My Device: Z10 • Z30 • PlayBook

Re: Adding images dynamically - tutorial examples do not work

I managed to figure it out. The example provided in the tutorial is defnitely wrong, which is very annoying and frustrating for those of us learning to code for BB10. Not only this, but the "barrier to entry" is already difficult enough, and if Blackberry want their ecosystem to flourish, the documentation and tutorials should be accurate and easy to follow.

 

The constructor should be something like:

 

TestApp::TestApp(bb::cascades::Application *app) : QObject(app)
{
  QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);
  qml->setContextProperty("injection", this);
  Page *appPage = qml->createRootObject<Page>();
  mRootContainer = appPage->findChild<Container*>("rootContainer");
  app->setScene(appPage);
}