Can't bind UI description GtkStack in C code

I have this UI description:

   <object class="GtkStack" id="stack_projects_setup">
   <property name="visible-child-name">page_project_create</property>
     <object class="GtkBox" id="page_projects_list">
        <property name="name">page_projects_list</property>
        <property name="title" translatable="yes">Projects List</property>
       <object class="GtkGrid" id="page_project_create">
         <property name="name">page_project_create</property>
         <property name="title" translatable="yes">Create Project</property>

And in the C source code, this:

struct _MemoAppProjects
  GtkWindow parent;
  GtkButton *btn_ok;
  GtkButton *btn_cancel;
  GtkButton *btn_add_project;
  gboolean btn_ok_clicked;
  gboolean btn_cancel_clicked;
  // GtkListStore *store_projects;
  GtkWidget *treeview;
  GtkWidget *stack_projects_setup;
  GtkWidget *page_projects_list;
  GtkWidget *page_project_create;

static void
memoapp_projects_class_init (MemoAppProjectsClass *class)
  g_print ("%s\n", "memoapp projects class init");

  gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (class),

  gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (class), MemoAppProjects, btn_ok);
  gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (class), MemoAppProjects, btn_cancel);
  gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (class), MemoAppProjects, btn_add_project);
  gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (class), MemoAppProjects, treeview);
  gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (class), MemoAppProjects, stack_projects_setup);
  gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (class), MemoAppProjects, page_projects_list);
  gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (class), MemoAppProjects, page_project_create);

And when I try to use *self->stack_projects_setup in some method, I get an assertion error:

gtk_stack_get_visible_child_name: assertion ‘GTK_IS_STACK (stack)’ failed

Same if I use GTK_STACK macro.

The builder UI description itself generates a warning just by running the application:

Child name ‘page_project_create’ not found in GtkStack

The stack and the pages of the stack are named with the id and name attribute. Not sure what I am missing.

So, these are the two problems I am facing in attempting to use GtkStack. Is there any documentation I failed to read that would clarify things on this?

Here are the two files (work in progress) related to this problem, in case it helps: UI xml file, and the C file.

Any help would be appreciated!

Does the following make a difference?

-   <template class="MemoAppProjects">
+   <template class="MemoAppProjects" parent="GtkWindow">

@fmuellner Thanks for helping. I’m sorry to say that the situation remains the same.

Well, I have said that I was missing something, which turned out to be the case.

My callback function was declared with this signature:

btn_add_project_cb (MemoAppProjects *self)

Which is wrong, of course. It has to declare the self object as the second parameter. This worked just fine:

btn_add_project_cb (GtkButton *btn, MemoAppProjects *self)
    // Now self->stack_projects_setup is indeed the stack object.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.