Re: refBuilder->get_widget_derived usage
- From: Markus Kolb <markus kolb+gtkmm tower-net de>
- To: gtkmm Mailinglist <gtkmm-list gnome org>
- Subject: Re: refBuilder->get_widget_derived usage
- Date: Sat, 28 Feb 2015 12:12:18 +0100
Am 2015-02-28 10:47, schrieb Markus Kolb:
Hi,
I'm currently stuck and need your help...
I'd like to "load" a child Box from a glade-file to a derived class.
But on usage of the ContainerServer* returned by static
ContainerServer* create(),
I get a segv:
p_notebook_game->append_page(*p_container_server, _("Server"));
#0 0x00007ffff79f10b3 in Gtk::Notebook::append_page(Gtk::Widget&,
Gtk::Widget&) () at /usr/lib64/libgtkmm-3.0.so.1
#1 0x000000000041a2a5 in on_dialog_new_response(int) (response_id=-5)
at battleship.cpp:450
#2 0x00007ffff79bbbc7 in () at /usr/lib64/libgtkmm-3.0.so.1
[...]
Needs the refBuilder be available and isn't it possible to hide it?
So does the *p_cs get deleted when refBuilder gets deleted?
Or why this doesn't work?
How to do it? The examples only "load" main-dialogs.
I've changed my create() to a
static ContainerServer* create(const Glib::RefPtr<Gtk::Builder>&
refBuilder);
Then it works. So my assumption seems to be right.
I think I can live with it.
class ContainerServer : public Gtk::Box
{
public:
ContainerServer(BaseObjectType* cobject, const
Glib::RefPtr<Gtk::Builder>& refBuilder);
static ContainerServer* create();
private:
Gtk::TreeView* m_p_treeview;
} ;
ContainerServer::ContainerServer(BaseObjectType* cobject, const
Glib::RefPtr<Gtk::Builder>& refBuilder) : Gtk::Box(cobject)
{
refBuilder->get_widget("treeview_server", m_p_treeview);
m_p_treeview->get_model();
// TODO: liststore stuff
}
ContainerServer* ContainerServer::create()
{
// Load the GtkBuilder file and instantiate its widgets
Glib::RefPtr<Gtk::Builder> refBuilder = Gtk::Builder::create();
try
{
refBuilder->add_from_file(Glib::build_filename(Configuration::get().get_datadir(),
"bs_server.glade"));
} catch (const Glib::FileError& ex)
{
g_critical("FileError: %s", ex.what().c_str());
return 0;
} catch (const Glib::MarkupError& ex)
{
g_critical("MarkupError: %s", ex.what().c_str());
return 0;
} catch (const Gtk::BuilderError& ex)
{
g_critical("BuilderError: %s", ex.what().c_str());
return 0;
}
ContainerServer* p_cs = 0;
refBuilder->get_widget_derived<ContainerServer>("box_server", p_cs);
return p_cs;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]