cglibgio

How do I actually provide a GType for the first argument of the GListStore constructor in C?


I need to use a GListStore for a specific GTK API in a C program, and as such I'm trying to create one so I can fill it with some elements. Looking at the documentation for g_list_store_new (), I need to provide a GType as the first and only parameter to the aforementioned constructor . However, the documentation doesn't specify what a GType really is or how I can acquire one, and nor does it link to any references as far as I can tell. I tried searching the web and found some source code that mentions G_TYPE_POINTER (among other types, but this was the one that seemed like what I wanted given that I'm storing strings). However, g_list_store_new (G_TYPE_POINTER) results in an assertion failure:

GLib-GIO-CRITICAL **: 11:42:49.339: g_list_store_new: assertion 'g_type_is_a (item_type, G_TYPE_OBJECT)' failed
Trace/breakpoint trap (core dumped)

What should I provide as first parameter to this constructor to create a GListStore?


Solution

  • The type must be a subclass of GObject, so raw pointers or boxed structs don’t work.