[Interest] Migrating QWeakPointer to Qt5
Bo Thorsen
bo at vikingsoft.eu
Fri May 6 08:15:02 CEST 2016
Den 06-05-2016 kl. 07:35 skrev Tom Isaacson:
> 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?
With this code, you need QPointer.
Bo Thorsen,
Director, Viking Software.
--
Viking Software
Qt and C++ developers for hire
http://www.vikingsoft.eu
More information about the Interest
mailing list