[Qt-interest] save QObject based classes in vector with auto delete functionality
Malyushytsky, Alex
alex at wai.com
Tue Oct 20 21:11:09 CEST 2009
Sorry for giving a link and not checking the class description.
Looks like could not rely on my memory about class functionality :P
Here is a link to QSharedPointer:
http://doc.trolltech.com/4.5/qsharedpointer.html
-----Original Message-----
From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Dan Milburn
Sent: Tuesday, October 20, 2009 5:17 AM
To: qt-interest at trolltech.com
Subject: Re: [Qt-interest] save QObject based classes in vector with auto delete functionality
Malyushytsky, Alex wrote:
>>> I have a class derived from QThread (Classes which do Curve Fitting).
> Now I want to save these Classes (which contain the fit results) in a
> vector.
>
> Don't mix classes and objects.
>
> As far as I can recall QT3 had QPtrVector class, which does not exist in QT4.
> So I believe there is no class which handles array of pointers.
>
> But you can:
> - derive your class from QValueVector< MyClass* > and add code to destructor to delete all pointers there.
> ( 1 loop 3 lines of the code )
> - instead of the raw pointer use guarded pointer like QPointer http://doc.trolltech.com/4.5/qpointer.html
> (extra memory allocation, which might be undesired if you have large array)
QPointer does not delete the pointed-to object when it goes out of
scope. The only Qt pointer class which would achieve the desired
behaviour here is QSharedPointer. Subclassing QVector would probably be
better as long as you take account of the fact that the base class
destructor is not virtual.
However I would suggest that the fit results be moved into a separate
class from the QThread. Having auto-deletion of QThread objects seems
like a very bad idea.
Dan
_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest
---------------------------------------------------------------------------------------------------
Weidlinger Associates, Inc. made the following annotations.
"This message and any attachments are solely for the intended recipient and may contain confidential or privileged information. If you are not the intended recipient, any disclosure, copying, use, or distribution of the information included in this message and any attachments is prohibited. If you have received this communication in error, please notify us by reply e-mail and immediately and permanently delete this message and any attachments. Thank you."
"Please consider our environment before printing this email."
More information about the Qt-interest-old
mailing list