Gtk.ClosureExpression / CClosureExpression in Vala

I want to get value from GListModal item via GtkClosureExpression callback function, the follow code compile succesfully, but throw exception while running:

GLib.Closure closure;
Gtk.Expression expression;
Gtk.ConstantExpression const_expr;
Gtk.SignalListItemFactory factory;
for(int index = 0; index < data_model.columns.size; index++) {
    factory = new Gtk.SignalListItemFactory();
    factory.set_data<int>("INDEX", index);
    factory.setup.connect(column_setup_handler);
    factory.bind.connect(column_bind_handler);
    column = new Gtk.ColumnViewColumn(data_model.columns[index].name, factory);
    column.expand = true;
    column.resizable = true;

    const_expr = new Gtk.ConstantExpression(typeof(int), index);
    closure = new GLib.CClosure((Callback)get_value_by_index, null, null);
    expression = new Gtk.ClosureExpression (typeof(string), closure, { const_expr });
    column.sorter = new Gtk.StringSorter(expression);
    this.grid.append_column(column);
}

string get_value_by_index(RowModel? row_model, int index)
{
    GLib.warning("get_value_by_index......");
    GLib.warning("Parameter: %s", row_model.values[0].to_string());
    return row_model.values[0].to_string();
}
(app.exe:12692): GLib-CRITICAL **: 10:51:50.066: g_utf8_casefold: assertion 'str != NULL' failed
(app.exe:12692): GLib-CRITICAL **: 10:51:50.066: g_utf8_collate_key: assertion 'str != NULL' failed

Try the another solution, its work fine.

const_expr = new Gtk.ConstantExpression(typeof(int), index);
expression = new Gtk.CClosureExpression(typeof(string), null, { const_expr }, (Callback)get_value_by_index, null, null);
column.sorter = new Gtk.StringSorter(expression);
this.grid.append_column(column);

static string get_value_by_index(RowModel? row_model, int index)
{
    return row_model.values[index].to_string();
}

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