[Interest] Proper use of SharedPointer/WeakPointer

Pritam pritam_ghanghas at infosys.com
Thu Feb 23 15:20:11 CET 2012


On Thursday 23 February 2012 07:40 PM, Jason H wrote:
> I have an object database (objects inherit QObject) which is 
> queryable. The result of the query is a list of zero or more objects. 
> I don't want to give pointers themselves, as people could call delete 
> on them and destroy the database.
>
> In this example:
> QList<QObject*> results = objDb.query();
>
> I want results to be weak pointers. such that delete results.at(0) 
> will not actually delete an object, just the pointer in the list.
> When creating my object database, do I store real pointers or 
> QSharedPointers?
> In the list am I returning QSharedPointers or QWeakPointers?
>
> Is there a better pointer class that I should be using?
>
> Thanks.
I didn't understand why you need to use QWeakPointer. I think it will be 
better if you use QSharedPointer everywhere. Unless you want to control 
the life time of your objects strictly from within your object database 
and it doesn't matter to you whether some one else is using that object 
or not. That will result in weak pointer checks everywhere else.

-- 
Regards,
Pritam


**************** CAUTION - Disclaimer *****************
This e-mail contains PRIVILEGED AND CONFIDENTIAL INFORMATION intended solely 
for the use of the addressee(s). If you are not the intended recipient, please 
notify the sender by e-mail and delete the original message. Further, you are not 
to copy, disclose, or distribute this e-mail or its contents to any other person and 
any such actions are unlawful. This e-mail may contain viruses. Infosys has taken 
every reasonable precaution to minimize this risk, but is not liable for any damage 
you may sustain as a result of any virus in this e-mail. You should carry out your 
own virus checks before opening the e-mail or attachment. Infosys reserves the 
right to monitor and review the content of all messages sent to or from this e-mail 
address. Messages sent to or from this e-mail address may be stored on the 
Infosys e-mail system.
***INFOSYS******** End of Disclaimer ********INFOSYS***
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20120223/cbe5b119/attachment.html>


More information about the Interest mailing list