I'm working on a GTK program written in C. In a specific function, adw_combo_row_set_model ()
, I need to provide a GListModel
. I have a GList
. How can I either convert the GList into a GListModel or otherwise provide a view of the GList that is compatible with GListModel?
I need to provide a
GListModel
. I have aGList
. How can I either convert theGList
into aGListModel
or otherwise provide a view of theGList
that is compatible withGListModel
?
Despite "List" appearing in both names, GListModel
isn't really related to GList
. There is no direct conversion.
You have two main options:
Choose an existing implementation of GListModel
, such as GListStore
, instantiate it, and copy the elements of your GList
into it.
Write your own implementation of GListModel
that wraps a GList
and provides a view of it.
Depending on where the GList
is coming from and what else you need to be able to do with it, you might have a secondary option of using a GListModel
throughout. Then no special action would be required to get one.