Cannot add unnamed child to GtkStack
In Tetravex, I have a GtkStack which will only be used one time: the restore_button
is only shown at startup, and is replaced by the undo_redo_box
once restoration is done or not available anymore. The undo_redo_box
is named, while the restore_button
doesn’t need to be:
restore_stack = new Stack ();
restore_stack.add_named (undo_redo_box, "undo-redo-box");
Button restore_button = new Button.with_label (_("Restore last game"));
restore_button.show ();
restore_button.insert_before (restore_stack, /* insert last */ null);
restore_stack.set_visible_child (restore_button);
But I obtain a strange error at window creation, and the button is not displayed:
(gnome-tetravex:184753): Gtk-WARNING **: 18:33:46.814: Given child of type 'GtkButton' not found in GtkStack
In Gtk3, I used the same code but using:
restore_stack.add (restore_button);
instead of:
restore_button.insert_before (restore_stack, /* insert last */ null);
In Gtk4, I can make things work replacing the same line by:
restore_stack.add_named (restore_button, "test");
Here is a backtrace of the problem, in case it helps:
Starting program: /var/home/aton/jhbuild/install/bin/gnome-tetravex
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
[New Thread 0x7fffe8d6a640 (LWP 186273)]
[New Thread 0x7fffe3fff640 (LWP 186274)]
[New Thread 0x7fffe282c640 (LWP 186275)]
[New Thread 0x7fffe1fc9640 (LWP 186276)]
(gnome-tetravex:186267): Gtk-WARNING **: 18:50:41.093: Given child of type 'GtkButton' not found in GtkStack
Thread 1 "gnome-tetravex" received signal SIGTRAP, Trace/breakpoint trap.
g_log_writer_default (log_level=<optimized out>, log_level@entry=G_LOG_LEVEL_WARNING,
fields=fields@entry=0x7fffffffd100, n_fields=n_fields@entry=6,
user_data=user_data@entry=0x0) at ../../checkout/glib/glib/gmessages.c:554
554 G_BREAKPOINT ();
(gdb) bt
#0 g_log_writer_default (log_level=<optimized out>, log_level@entry=G_LOG_LEVEL_WARNING,
fields=fields@entry=0x7fffffffd100, n_fields=n_fields@entry=6,
user_data=user_data@entry=0x0) at ../../checkout/glib/glib/gmessages.c:554
#1 0x00007ffff7cc2fa7 in g_log_structured_array (n_fields=6, fields=0x7fffffffd100,
log_level=G_LOG_LEVEL_WARNING) at ../../checkout/glib/glib/gmessages.c:1925
#2 g_log_structured_array (log_level=G_LOG_LEVEL_WARNING, fields=0x7fffffffd100, n_fields=6)
at ../../checkout/glib/glib/gmessages.c:1898
#3 0x00007ffff7cc39b1 in g_log_structured_standard (log_domain=0x7ffff78a5225 "Gtk",
log_level=G_LOG_LEVEL_WARNING, file=<optimized out>, line=<optimized out>,
func=<optimized out>, message_format=<optimized out>)
at ../../checkout/glib/glib/gmessages.c:1982
#4 0x00007ffff767ae14 in gtk_stack_set_visible_child (stack=0x79d3a0, child=0x751c10)
at ../../checkout/gtk+/gtk/gtkstack.c:1850
#5 0x000000000040eab3 in tetravex_real_startup (base=0x45a2c0)
at ../../checkout/gnome-tetravex/src/gnome-tetravex.vala:371
#6 0x00007ffff7dab12e in _g_closure_invoke_va (closure=0x455500, return_value=0x0,
instance=0x45a2c0, args=0x7fffffffd948, n_params=0, param_types=0x0)
at ../../checkout/glib/gobject/gclosure.c:873
#7 0x00007ffff7dc2f7e in g_signal_emit_valist (instance=0x45a2c0, signal_id=<optimized out>,
detail=0, var_args=var_args@entry=0x7fffffffd948)
at ../../checkout/glib/gobject/gsignal.c:3403
#8 0x00007ffff7dc3162 in g_signal_emit (instance=<optimized out>, signal_id=<optimized out>,
detail=<optimized out>) at ../../checkout/glib/gobject/gsignal.c:3550
#9 0x00007ffff7eca772 in g_application_register (application=application@entry=0x45a2c0,
cancellable=cancellable@entry=0x0, error=error@entry=0x7fffffffda68)
at ../../checkout/glib/gio/gapplication.c:2204
#10 0x00007ffff7ecab4a in g_application_real_local_command_line (application=0x45a2c0,
arguments=0x7fffffffdad0, exit_status=0x7fffffffdacc)
at ../../checkout/glib/gio/gapplication.c:1106
#11 0x00007ffff7ecae4e in g_application_run (application=0x45a2c0, argc=-9524,
argv=<optimized out>) at ../../checkout/glib/gio/gapplication.c:2528
#12 0x0000000000408735 in tetravex_main (args_length1=1, args=0x7fffffffdc28)
at ../../checkout/gnome-tetravex/src/gnome-tetravex.vala:147
#13 main (argc=1, argv=0x7fffffffdc28)
at ../../checkout/gnome-tetravex/src/gnome-tetravex.vala:133