[Interest] How can I use QPointer as an argument?
Bo Thorsen
bo at vikingsoft.eu
Tue Jan 13 10:58:20 CET 2015
Den 13-01-2015 kl. 04:13 skrev Guenther Boelter:
> I have a 'small' problem and my timeline is running so fast ...
>
> How can I use QPointer as an argument? A simple
>
> void myFunction( QPointer *myPointer )
> {
> // do something
> }
>
> myFunction( myPointer );
>
>
> returns 'error: ‘QPointer’ is not a type'.
You don't need to copy the QPointer. A QPointer is a weak pointer class.
It is told by the object it holds, if it's deleted, and then switch to a
null pointer.
So in your case, you simply give the object it holds to your function
instead.
If you want to, you can create a QPointer in your function.
void myFunction(QObject* o) {
QPointer p(o);
// do something
}
QPointer p(theRealObject);
myFunction(p.data());
I hope this helps.
Bo.
--
Viking Software
Qt and C++ developers for hire
http://www.vikingsoft.eu
More information about the Interest
mailing list