Viewport's child has problem finding parent component


Hello friends,

I have some problems facing with viewport
In AComponent has Viewport.
In Viewport BComponent is added with setViewedComponent(new BComponent()).
In BComponent’s resized() while i try to use getParentComponent(), there is component i can find here.

Can any one point, what is the problem ? Thank you.


BComponent doesn’t get added as a child component until it has finished being created. Remember that, effectively, in the line…

… the bit in the brackets is evaluated before the function call is actually made.
BComponent is therefore fully constructed before the Viewport gets a look at it (and so it doesn’t have a parent yet).


Thanks haydxn. (Problem is Solved)

Exactly you are right, My first mistake was i was using resized inside constructor, that brought me to this whole problem.

After viewport’s setViewedComponent(new BComponent());
I applied viewport’s getViewedComponent()->resized();

And that solves all. It is so simple here. :smiley: