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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Contributor
Posts: 15
Registered: ‎07-15-2013
My Device: Blackberry Z10
My Carrier: Verizon

When I delete the parent of a qobject, will the qobject be deleted even if it was allocated to the heap?

For instance, if I am something list this:

 

socket = new QSslSocket(this); 

 

where this is a socket wrapper. If I explicitly delete the socket wrapper, will it also delete the QSslSocket object or do I need to do it myself?

 

Also, is there an accepted way of stopping and deleting threads. When I emit a signal to the quit slot, is it eventually going to emit a finished signal? Is it better to delete the thread or the worker I moved on to it first?

 

Thanks.

Highlighted
Retired
Posts: 170
Registered: ‎09-06-2010
My Device: None
My Carrier: None

Re: When I delete the parent of a qobject, will the qobject be deleted even if it was allocated to the heap?

Essentially yes. If you do the following:

 

QObject* parent = new QObject();
QObject* child = new QObject(parent);
delete parent;

 there is a relationship established between the parent and the child instances. In this example parent and child are both instances of QObject but the same relationship is established if the classes derive from QObject. The parent instance contains a list of pointers to its child object instances.

 

When you delete the parent, the child object instances each have their destructors called automatically where they free up their own resources. The key point is that you need to ensure that any classes you use, or create yourself derive, from QObject for this to work. If they don't you need to take care of cleaning up yourself.

 

Regarding threads and the correct way to use them in Qt. There is a quite a bit of "opinion" on how you should do this properly due to some poor Qt documentation in the past on overriding the run() method. There is a good discussion of this here:

 

http://supportforums.blackberry.com/t5/Native-Development/Correct-way-to-use-QThreads/m-p/2299837/hi...

 

which covers the topic as well as providing links to the some of the original articles that clarified the preferred way to do it.