[Qt-interest] What is the use of QWeakPointer

Matthias Pospiech matthias.pospiech at gmx.de
Fri Apr 9 11:30:49 CEST 2010


I was trying to use QWeakPointer, but I do not see how to use it as a 
replacement for c++ pointers.

First I can not contruct it with a QThread based class:

checkPositionThread(new PiezoJenaControllerCheckPositionThread(this, this))

with

class PiezoJenaControllerCheckPositionThread : public QThread
{
    Q_OBJECT
...

gives the error:
1>.\include\matthias\PiezoJena\PiezoJenaController.cpp(28) : error 
C2664: 'QWeakPointer<T>::QWeakPointer(const QWeakPointer<T> &)': 
Konvertierung des Parameters 1 von 
'PiezoJenaControllerCheckPositionThread *' in 'const QWeakPointer<T> &' 
nicht möglich
1>        with
1>        [
1>            T=PiezoJenaControllerCheckPositionThread
1>        ]
1>        Ursache: Konvertierung von 
'PiezoJenaControllerCheckPositionThread *' in 'const QWeakPointer<T>' 
nicht möglich
1>        with
1>        [
1>            T=PiezoJenaControllerCheckPositionThread
1>        ]
1>        Quelltyp konnte von keinem Konstruktor angenommen werden, oder 
die Überladungsauflösung des Konstruktors ist mehrdeutig

And further it has not -> Operator so that I can not access the pointer 
as if it was a normal pointer. This especially is a point that I do not 
understand.
How shall I use a pointer class if I can not use the pointer in the way 
pointers are accessed normaly?

Basically I have now switched back to c/c++ pointers until I understand 
how this smart pointer or any other smart pointer is supposed to be used.
Maybe anyone can help me out with further information or an basic example?

Matthias



More information about the Qt-interest-old mailing list