[Qt-interest] save QObject based classes in vector with auto delete functionality
Malyushytsky, Alex
alex at wai.com
Tue Oct 20 01:35:10 CEST 2009
>> 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)
Regards,
Alex
-----Original Message-----
From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Matthias Pospiech
Sent: Monday, October 19, 2009 5:41 AM
To: Qt-interest
Subject: [Qt-interest] save QObject based classes in vector with auto delete functionality
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.
That has the principle problem that I cannot copy a QObject. I could
construct all classes as pointers and save only the pointers.
However I do not want to manually take care of the deletion.
Is there a Pointer class which I can use, which automatically takes care
of the deletion of the objects in the vector?
Matthias
_______________________________________________
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