In Gtk I have a class hierarchy like this:
Gtk::ListStore is derived from Gtk::TreeModel
From a Gtk::TreeView
I can get with get_model()
a Glib::RefPtr<Gtk::TreeModel>
If I use in my Gtk::Treeview
a Gtk::ListStore as a Gtk::TreeModel and call get_model()
I get a Glib::RefPtr< TreeModel >
But I want call member functions of Gtk::ListStore.
How can I cast the Glib::RefPtr<Gtk::TreeModel>
down to Glib::RefPtr<Gtk::ListStore>
. Is there a standard way or is there a hack needed or how is the typical procedure to act with views and different store types. Are there any checking functions so that the upcast can done safe, maybe with compile time checking or if not possible during runtime? Any hint to any documentation.
For downcasting use
Glib::RefPtr<Gtk::ListStore> ptrDerived = Glib::RefPtr<Gtk::ListStore>::cast_dynamic(treeModel);
documentation
Upcasting is implicit as shown in the documentation linked by nikitoz.
However, Gtk::ListStore
is not a base class of Gtk::TreeModel
but other way round. You are asking about downcasting, not upcasting. For that, you need explicit dynamic cast. Glib::RefPtr
has a static member function template cast_dynamic
which does exactly that. You can find it in the class reference
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With