Re: Cannot `dynamic_cast` custom wrapped widget from Gtk::Builder
- From: Josh Bialkowski <josh bialkowski gmail com>
- To: Kjell Ahlstedt <kjellahlstedt gmail com>
- Cc: gtkmm-list <gtkmm-list gnome org>
- Subject: Re: Cannot `dynamic_cast` custom wrapped widget from Gtk::Builder
- Date: Tue, 5 May 2020 10:45:28 -0700
> Gtk::wrap_init() is called from Gtk::Main (deprecated) and from Gtk::Application.
Ah, ok, this is the problem then. It is an ODR violation.
> Have you created your own Gtk::wrap_init(), containing everything the standard Gtk::wrap_init() contains, plus your own Glib::wrap_register() call?
Nope,
my implementation[1] is generated by `
generate_wrap_init.pl` and just contains the call to `wrap_register` and `get_type`. I guess one assumption by `
generate_wrap_init.pl` is that whatever library you are wrapping isn't creating widgets in the `Gtk` namespace. Which... is probably a reasonable assumption.
> In that case I suppose there are two Gtk::wrap_init() functions, one in libgtkmm-3.0 and another one in your lib file. Which one will the linker select?
Yup, I concur this is the problem. I'm pretty sure that the linker will select the first one encountered so it will depend on the order that the libraries show up on the link line. As long as my library is on the link line first then "things work". Otherwise not. Since the `Gtk::wrap_init` inside `gtkmm` is not getting called. There is likely to be a latent bug that I just haven't encountered yet.
Thanks again for your insight.
[1]:
https://github.com/cheshirekow/tangent-gtk/blob/master/tangent/gtkutil/mm/wrap_init.cc
On 2020-05-04 23:45, Josh Bialkowski wrote:
> > You said in a previous post that you execute...
>
> Wellllll... this is executed inside the generated `wrap_init()` which
> is part of the `Gtk::` namespace (in hindsight, a bad idea) and
> apparently this function is not getting called. If I call it directly
> in `main()` then things are working. At first, I thought there must be
> a `Gtk::wrap_init()` somewhere already in gtkmm but I can't find it,
> so the other possibility is maybe a build system error and a left over
> build artifact somewhere. Maybe? In any case, to summarize, my
> understanding is that:
>
> 1. I used _CLASS_GOBJECT which generates a Glib::wrap returning a
> `Glib::RefPtr` instead of _CLASS_GTKOBJECT which generates Glib::wrap
> returning a raw pointer. This may or may not have contributed to the
> particular problem, as perhaps some type/overload resolution somewhere
> depended on this. Or it was a latent error that wasn't involved in
> this particular problem.
> 2. Lacking a `wrap_init`, I was not calling `Glib::wrap_register`,
> which sounds like the most likely culprit
> 3. Even after I generated `wrap_init()`, it apparently wasn't getting
> called. Possibly due to some link-order issue or a stale build
> artifact or something.
>
Gtk::wrap_init() is called from Gtk::Main (deprecated) and from
Gtk::Application.
Have you created your own Gtk::wrap_init(), containing everything the
standard Gtk::wrap_init() contains, plus your own Glib::wrap_register()
call? In that case I suppose there are two Gtk::wrap_init() functions,
one in libgtkmm-3.0 and another one in your lib file. Which one will the
linker select?
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]