Vala confused me about construction functions!


        var search_entry = new Gtk.SearchEntry ();
        var sfilter = new Gtk.StringFilter (new Gtk.PropertyExpression (typeof (ItemPoets), null, "name"));
        var filter = Gtk.Filter (sfilter);
        filter.set_match_mode (Gtk.StringFilterMatchMode.PREFIX);
        var filter_model = new Gtk.FilterListModel (single_selection, filter);
        //filter.set_search ("test");
        search_entry.bind_property ("text", filter, "search", 0);

if I write: var filter = Gtk.Filter (sfilter);

error: use `new’ operator to create new objects

if I write: var filter = new Gtk.Filter (sfilter);

error: Access to non-public constructor `’

Does anyone guide me how to do this?

Gtk.StringFilter is a subclass of Gtk.Filter so you don’t need it at all here.

If the function requires a Gtk.Filter, you should just cast the Gtk.StringFilter to one.

In general i don’t think you are expected to use Gtk.Filter directly unless you are subclassing it.

1 Like

Gtk.Filter does not have a public constructor: you can only subclass it, or instantiate one of its subclasses:

  • Gtk.BoolFilter
  • Gtk.CustomFilter
  • Gtk.FileFilter
  • Gtk.MultiFilter
  • Gtk.StringFilter

A Gtk.StringFilter is already a Gtk.Filter, so you don’t create a Gtk.Filter instance wrapping a Gtk.StringFilter: you cast a Gtk.StringFilter to Gtk.Filter. See the tutorial for “dynamic type casting”.

1 Like

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