View Full Version : QSharedPointer forward declare, compile warnings persist.

29th April 2013, 20:12
QSharedPointer gives nasty compile time warnings if the class whose smart pointer is being made is forward declared. QScopedPointer documentation has some documentation on how to avoid warnings with forward declaration. As has been pointed out in this bug, works for QSharedPointer too...

However compiler warnings persist for me... consider code...

class MyPrivateClass; // forward declare MyPrivateClass

class MyClass
QList<QScopedPointer<MyPrivateClass> > privatePtr; //QList QScopedPointer to forward declared class

MyClass(); // OK
~MyClass(); // Not a VIOLATION - Destructor must not be inline

Q_DISABLE_COPY(MyClass) // OK - copy constructor and assignment operators
// are now disabled, so the compiler won't implicitely
// generate them.

Any way to avoid the warnings.. the qt version is 4.8.4... the bug is apparently fixed in 5.0 but can't shift.

30th April 2013, 00:23
great, thanks.

Do you have a question?

30th April 2013, 10:42
You cannot put QScopedPointers into a QList because to do so requires the ability to copy the QScopedPointer, which is is expressly disabled by a private copy constructor. This generates nasty errors, not warnings.

If you were using QSharedPointer then the issue goes away.