GtkChild annotion tries to bind wrong element in child template #284
Labels
No labels
bug
dependencies
documentation
duplicate
enhancement
github_actions
good first issue
help wanted
invalid
java
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
java-gi/java-gi#284
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
My app has two composite templates.
One is for an AdwWindow and one is for an AdwNavigationPage.
I want to include one template as a child of the other.
If I do this according to the gtk docs the widgets render fine, but if I try to bind a child from my AdwNavigationPage template,
the program attempts to bind org.gnome.adw.NavigationPage instead of org.gnome.gtk.MenuButton
as it should be.
(java:21735): java-gi-CRITICAL **: 20:55:26.626: Cannot get template child headerbarMenuButton in class grooveboat.MusicChooser: Can not set org.gnome.gtk.MenuButton field grooveboat.MusicChooser.headerbarMenuButton to org.gnome.adw.NavigationPageI've reproduced the problem, but don't know what the cause is yet. While assigning the template child objects to the Java fields, the class instance is a NavigationPage (the parent type of MusicChooser).
Aha, found it.
While processing the template ui files, Gtk constructs a new (native) instance of the MusicChooser gtype, and then a java "wrapper instance" is created for it. But your MusicChooser java class doesn't have a constructor for an existing native instance (i.e. a memory address).
Add this constructor to the
MusicChooserclass:This is documented here but I can imagine that this is easily overlooked...
Thank you so much for the quick response.
Totally my bad for not reading the docs properly. I didn't think this would be the issue. Maybe the logs could tell the user to
checks this if this type missmatch occurs.
I added the constructor, and now the native code can instantiate this class.
However, if I register this class using Types.register() and annotate the class with RegisteredType,
the instantiated object doesn't have any children anymore, as if it had ignored the GtkTemplate annotation now.
The object is correctly instantiated if I manually instantiate the class once in the app instead of registering it,
but then it gets instantiated twice, which causes funky behavior.
I might be missing something again but I currently can't find what might be causing this.
It would be nice if you could help me out once more 😅.
You need to use
TemplateTypes.register()instead.In the upcoming 0.13.0 release this will be automatic, and I already updated the docs, sorry.
Btw I agree that the error log for the missing constructor can be improved, please keep the bug open so I don't forget.
Oh I see. Now it works.
Thanks again.
I will keep the issue open.