diamondburned / gotk4

Autogenerated GTK4 bindings for Go
GNU Affero General Public License v3.0
498 stars 19 forks source link

gioutil.ListModel.Item() not returning concrete Go type anymore #146

Closed abenz1267 closed 2 months ago

abenz1267 commented 2 months ago

Hi,

with the new release *gioutil.ListModel[modules.Entry] doesn't return modules.Entry anymore, but instead the glib.Object. I tried casting like this entry := ui.items.Item(ui.selection.Selected()).Cast().(interface{}).(*modules.Entry) ... without success.

I bet i'm missing a simple solution here...

Regards

abenz1267 commented 2 months ago

Ok, i figured it out:

    listModelType := gioutil.NewListModelType[modules.Entry]()
    items := listModelType.New()

You can then retrieve the underyling value via

        valObj := ui.items.Item(item.Position())
        val := ui.listModelType.ObjectValue(valObj)

In case someone else runs into this.

abenz1267 commented 2 months ago

entry := gioutil.ObjectValue[T](val) works as well