PDA

View Full Version : How to cast QPointer<T> to QPointer<childT>



cafu
19th March 2010, 10:30
Hi there,

i have a small problem while casting from QPointer<T> to QPointer<ChildT>

I tried this.

QPointer<T> tObject=new T();
//QPointer<ChildT> childtObject=(QPointer<T>)tObjec;// this does not work;
QPointer<ChildT> childtObject=(ChildT*)(T*)tObjec;// this work;

high_flyer
19th March 2010, 10:38
try qobject_cast<T>

cafu
19th March 2010, 10:47
do you mean qobject_cast<childT> thanks for the fast answer

Lykurg
19th March 2010, 10:49
Since QPointer is a "normal" pointer at all you also could use
QPointer<T> tObject = new T();
QPointer<ChildT> childtObject = (ChildT*) tObjec.data();

cafu
19th March 2010, 10:51
to cast to the parentclass pointer and then to child class pointer is correct:


QPointer<T> tObject=new T();
QPointer<ChildT> childtObject=(ChildT*)(T*)tObjec;