Getting items from a GtkColumView / GListStore

I have a GtkColumnView with two columns.
Each row contains two GtkEntry widgets. The data from these are linked to a GListStore holding tuples.
The user can add and delete rows, after which the list is sorted.

I cannot work out how to get the data out of the GListStore! It’s like I have a write only memory :smirk_cat:
What is the procedure to iterate over a GListStore to read the data?

Is there another way to get the data from the GtkColumnView that I missed?

A GListStore is a concrete implementation of the GListModel interface. You use the list model API to iterate and access the data.

1 Like

Yes, that works! thanks.

At the moment I’m adding a data element to the GtkColumnView to hold a pointer to the GListStore because I couldn’t find an API way to access the GListStore from the GtlColumnView widget. This is way to hacky to be correct
… what is the correct way to get access to the GtkColumnView GListStore ?

There’s gtk_column_view_get_model(). You should really look at the API reference: all this information is available there, including:

  • the ancestors of a type
  • the interfaces implemented by a type
  • the methods inherited by a type from its ancestors and interfaces

Of course I saw that but the documentation says that this returns “GtkSelectionModel *”.
Looking at the documentation for GtkSelectionModel I see ways to get the selected items but not a general access to the store. Are you implying that I just need to cast the GtkSelectionModel to GListModel ?

:point_right: edit:
I just tried that and it did work… I’m perplexed as to how anyone would have arrived at that method using the documentation :scream_cat:

Did you go to the GtkSelectionModel page? If you do, you’ll see that it’s an interface, and any implementation of the GtkSelectionModel interface must also be a GListModel implementation, as it is a prerequisite of the type.

I don’t need to imply it: it’s clearly stated in the documentation.

The whole type system is based on well-defined inheritance rules: you need to become acquainted with them if you want to use the GTK API.

1 Like

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