Let's say I have this class:
class Bear
{
public:
Bear ();
Bear (Bear &other);
// ... methods
private:
BearInfo* m_pInfo;
};
Can I store Bear
objects in a QList<Bear>
by value? According to the documentation:
Internally,
QList<T>
is represented as an array of pointers to items of typeT
. IfT
is itself a pointer type or a basic type that is no larger than a pointer, or ifT
is one of Qt's shared classes, thenQList<T>
stores the items directly in the pointer array.
While my class just consists of a pointer, it is neither a pointer type nor a basic type, so it seems to me that the QList
will store pointers (Bear*
), which is not what I want. And since the BearInfo
structure must be mutable, I cannot derive Bear
from QSharedDataPointer
.
Any suggestions how I can enable this class to be stored by value in the Qt collections?
Use a QVector, the Qt Documentation states this:
QList, QLinkedList, and QVarLengthArray provide similar functionality. Here's an overview: