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
Developer
calicratis19
Posts: 163
Registered: ‎12-06-2012
My Device: Z10, Q10
My Carrier: BlackBerry
Accepted Solution

problem adding ListView to a container

I first add the the ListView to a container. Then after a particular condition I delete that container and create a new container. And then I try to add that ListView again to that newly created container. But it crashes when I try to add them.

if(currentPageContainer)
{
	currentPageContainer->remove(listView);
	delete(currentPageContainer);
}

currentPageContainer = new Container;
currentPageContainer->add(listView); // crashes here

 If I don't delete the container then it works fine.

Please use plain text.
Developer
Zmey
Posts: 1,507
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

Re: problem adding ListView to a container

Hi,

From the docs:
Once the control is removed, the container no longer references it, but it is still owned by the container.

Try adding
listView->setParent(NULL);
after removing the listView from the container, but before deleting the container.

Also, I suggest replacing "delete(...) with "delete currentPageContainer" to avoid accidentally calling a function. delete is an operator.

On this line:
currentPageContainer = new Container;
I suggest setting a parent: new Container(this) etc to avoid explicitly deleting it in destructor. It's ok to delete the object using operator delete even if the parent is set.

Andrey Fidrya, @zmeyc on twitter
Please use plain text.
Developer
calicratis19
Posts: 163
Registered: ‎12-06-2012
My Device: Z10, Q10
My Carrier: BlackBerry

Re: problem adding ListView to a container

So if I set a parent for a UIObject then when the parent is destructed the UIObject is also destructed?
Please use plain text.
Developer
Zmey
Posts: 1,507
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

Re: problem adding ListView to a container

Yes. This works for any QObject-derived classes.

Andrey Fidrya, @zmeyc on twitter
Please use plain text.
Developer
calicratis19
Posts: 163
Registered: ‎12-06-2012
My Device: Z10, Q10
My Carrier: BlackBerry

Re: problem adding ListView to a container

[ Edited ]

From the doc of container the inheritance heirarchi is like this,

bb::cascades::BaseObject->bb::cascades::UIObject->bb::cascades::VisualNode->bb::cascades::Control->bb::cascades::Container
But there is no QObject in the inheritance.

Please use plain text.
Developer
calicratis19
Posts: 163
Registered: ‎12-06-2012
My Device: Z10, Q10
My Carrier: BlackBerry

Re: problem adding ListView to a container

I am not being able to set the parent to 'this'. When I try to do currentPageContainer = new Container(this); the following error is occurred, 

 

 

Multiple markers at this line
	- no matching function for call to 
	 'bb::cascades::Container::Container(GeoNotification* const)'
	- candidates are:

 

Please use plain text.
Developer
Zmey
Posts: 1,507
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

Re: problem adding ListView to a container

[ Edited ]

Docs sometimes omit details. In the header file BaseObject inherits from QObject:

 

class BBCASCADES_EXPORT UIObject : public BaseObject {

...

class BBCASCADES_EXPORT BaseObject : public QObject, public QDeclarativeParserStatus {

 

It seems that Container doesn't have a constructor accepting QObject*. It can only accept another container as a parent. There's setParent function though which can be used instead:

 

container->setParent(this);

 

Is GeoNotification a custom class? I couldn't find it in Qt / BB headers. It will work only if the class inherits from QObject or any of it's subclasses.

 

UPD: depending on how the container is used, setting the parent may not be needed. Most functions such as x->add(something) automatically assign the parent if it was NULL.

 


Andrey Fidrya, @zmeyc on twitter
Please use plain text.
Developer
calicratis19
Posts: 163
Registered: ‎12-06-2012
My Device: Z10, Q10
My Carrier: BlackBerry

Re: problem adding ListView to a container

Yeah it's a custom class. setParent() works perfectly. Thanks. I appreciate the help very much:smileyhappy:
Please use plain text.