qt - C++ Subclassing, Inheritance and Casting -


this specific conundrum hard me explain i'll try best can.

in qt framework, there 2 classes: qtreewidget , qtreewidgetitem.

i have subclassed qtreewidgetitem:

 class myqtreewidgetitem : public qobject, public qtreewidgetitem {  ...  public:   int mycustomvariable; } 

i add qtreewidget doing like:

 myqtreewidgetitem *item = new myqtreewidgetitem; item->mycustomvariable = 10;  tree->addtoplevelitem(item); 

now, if ever need call tree->toplevelitem(x), qtreewidgetitem*.

however, i'm after myqtreewidgetitem* i:

 myqtreewidgetitem *theitem = (myqtreewidgetitem*)tree->toplevelitem(n); 

the problem theitem->mycustomvariable no longer equals 10.

is there way keep myqtreewidgetitem intact?

i don't know qq, try doing proper dynamic_cast<> verify whether object myqtreewidgetitem* (otherwise returns 0), performing pointer conversion (i'm not sure if c-style cast returning address of qobject). can print out pointers , more insight problem too.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -