[Qt-interest] Dereferencing QPointers

Ellen Kestrel dragonflykes at gmail.com
Sat Apr 18 04:36:18 CEST 2009


I have a class we'll call ClassA, which has as a data member a QList of
objects of ClassB, which inherits QObject.  This list is initially set by
calling an external function that returns a QList< QPointer<ClassB> >, which
is converted thusly:

QList< QPointer<ClassB> > tempList = func ();

while (tempList.size () > 0)  {
  ClassB *classB = tempList[0];
  classBList.append (*classB);
  tempList.removeAt (0);
  delete classB;
}

When compiling, it errors on the line that dereferences classB and adds it
to classBList.  The error says:

error: ‘QObject::QObject(const QObject&)’ is private

The external function has to create the objects as pointers, because they
have to be passed to other functions which have to be able to modify them
globally, so even if I changed it so that the function returned a
QList<ClassB> instead of a list of pointers, they would still have to be
dereferenced at some point.  I don't want to store them in ClassA as a list
of pointers, because then I would have to write a destructor to avoid memory
leaks, and there is no need for them to be pointers.  Does anyone know
what's going wrong, and how I can make this work?

- EK
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090417/944d073f/attachment.html 


More information about the Qt-interest-old mailing list