[Interest] Migrating QWeakPointer to Qt5

Tom Isaacson Tom.Isaacson at navico.com
Fri May 6 07:35:22 CEST 2016


I'm moving some Qt4.8.2 code which uses QWeakPointer to Qt5.6.  Simplifying a lot it looks like this:

class MySettings : public QObject
{
    Q_OBJECT
}

class MyClass : public QObject
{
    Q_OBJECT

private:
    QWeakPointer<MySettings> m_xSettings;
}

MyClass::MyClass(MySettings* pSettings, QObject* pParent)
    : QObject(pParent)
    , m_xSettings(pSettings)
{
}

but when I compile under Visual Studio 2013 I get this error:
error C2664: 'QWeakPointer<MyClass>::QWeakPointer(const QSharedPointer<T> &)' : cannot convert argument 1 from 'MySettings *' to 'const QWeakPointer<MySettings> &'

I tried changing the QWeakPointer to a QPointer but now I'm getting:
error C2440: 'static_cast' : cannot convert from 'QObject *' to MyClass *' (GeneratedFiles\Debug\moc_MyCode.cpp)

Is there a recommended method for migrating the use of QWeakPointer into Qt5?

Thanks.

Tom Isaacson




More information about the Interest mailing list