[Qt-interest] QList, copy problems
Andre Somers
andre at familiesomers.nl
Sun Oct 16 10:32:58 CEST 2011
Op 15-10-2011 23:58, ross at earz.ca schreef:
>> Am 15.10.11 16:17, schrieb Thiago Macieira:
> [snip for brevity's sake]
>
> I think we can all agree that the OP did not give us enough information to
> diagnose his problem. There are so many possibilities in how a program
> 'blows up'. Is it a C++ or Qt issue?
>
> Interesting exchange, nonetheless. I teach C++ to aspiring programmers
> and there is a lot of 'meat' in this thread for my advanced students.
>
OK, perhaps a take-home lesson then:
It might be smarter to use some kind of smart pointer as the thing that
you store in your list, instead of a raw pointer. In the case of
QObject*s, you could store a QPointer<QObject> instead, and in the
general case you would probably either store a shared pointer or a weak
pointer. The actual choices you make, depend on where the ownership of
the objects in your list resides, of course.
André
More information about the Qt-interest-old
mailing list