On Fri, May 6, 2016 at 8:35 AM, Tom Isaacson <tom.isaac...@navico.com>
wrote:

> I'm moving some Qt4.8.2 code which uses QWeakPointer to Qt5.6.
> Simplifying a lot it looks like this:
> [snippet ..]
> 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> &'

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

Yes, by actually using a QSharedPointer for the constructor (as
QWeakPointer is a weak reference to a shared pointer).


> 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)
>

Well you can't have implicit upcasting, so you should manually qobject_cast
to the derivied class, but this error doesn't really correspond to your
snippet. The pointer you have is referencing MySettings, not MyClass.

Kind regards,
Konstantin.
_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to