Upcasting not working

Started by jsinicro, 21 January 2018, 08:38:07

jsinicro

Hi, not sure whats going on but I have X number of Panels associated with a Tab so when I need to update the text in a Label in on of the panels with Panel::Ptr pnl = gui.get(pnlName) I get an error "NO viable conversion from shared_ptr<tgui::Widget> to shared_ptr<tgui::Panel> NO matter what I try I get the same result (i.e. panelVector[id]->get("labelName")->setText("newName); --setText not member of Widget).... any Ideas of what's going on I am using the latest .8 version on Mac... any thoughts appreciated...
Thx, Joe

texus

The get function will return a pointer to the Widget base class because it can't know the type of the widget. So I also added a get function with a template parameter that will do the cast for you and return the correct type:
Code (cpp) Select
tgui::Panel::Ptr pnl = gui.get<tgui::Panel>(pnlName);

If you ever have a Widget::Ptr that you have to upcast in another situation then you must use std::static_pointer_cast or std::dynamic_pointer_cast. I'm still looking for a good way to make that easier to do.

jsinicro

OK, I'll try that awesome... thx