How do I pass the correct parameter? (vala)

        ...
        var factory = new Gtk.SignalListItemFactory();
        factory.setup.connect(this.factory_setup);
        factory.bind.connect(this.factory_bind);
    }

    private void factory_setup (SignalListItemFactory f, ListItem item) {
        var label = new Gtk.Label ("");
        item.set_child (label);
    }

return error: a_page_poets.vala:32.31-32.48: error: Argument 1: Cannot convert from void PoetsPage.factory_setup (Gtk.SignalListItemFactory, Gtk.ListItem)' to delegate void Gtk.SignalListItemFactory.setup (Gtk.SignalListItemFactory, GLib.Object)’

   private void factory_setup (SignalListItemFactory f, Object item) {
       var label = new Gtk.Label ("");
       item.set_child (label);
   }

return error: a_page_poets.vala:69.9-69.22: error: The name set_child' does not exist in the context of GLib.Object’ (gobject-2.0)

What’s the solution?

You need to cast it:

    var listitem = item as Gtk.ListItem;

That should be implemented via a dynamic type-checking cast (GTK_LIST_ITEM()). You could also do a static cast: (Gtk.ListItem) item.

The signal prototype was changed in GTK 4.8 (breaking API for Vala, apparently), so you may find old code that used Gtk.ListItem.

1 Like

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