PDA

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



pkj
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...
https://bugreports.qt-project.org/browse/QTBUG-7302

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


class MyPrivateClass; // forward declare MyPrivateClass

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

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

private:
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.

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

Do you have a question?

ChrisW67
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.