Re: gtk_tree_model_filter_set_modify_func()



Russell Shaw wrote:

Tim Müller wrote:

On Tuesday 29 June 2004 18:25, Russell Shaw wrote:

In the following code, i can only get printed on the terminal window:
  n:0 val:(null)
I should get:
  n:0 val:abc

If i comment out the gtk_tree_model_filter_set_modify_func() line
then it works. What am i doing wrong? Gtk 2.4.3



... snip ...

void filtermodifyfunc(
                      GtkTreeModel *model,
                      GtkTreeIter *iter,
                      GValue *value,
                      gint column,
                      gpointer data)
{
    return;
}



you're supposed to set the value to something in that function, otherwise it will just stay initialised to 0/NULL ....


When i get the value to modify with gtk_tree_model_get() in the code below, it seems to recursively call filtermodifyfunc() and the process repeats until a
segfault:

void filtermodifyfunc(
                      GtkTreeModel *model,
                      GtkTreeIter *iter,
                      GValue *value,
                      gint column,
                      gpointer data)
{
    g_printf("passed\n");
    if(G_VALUE_HOLDS_STRING(value)){
        gchar *str;
        gtk_tree_model_get(model,iter,column,&str,-1);
        g_value_set_string(value,str);
        g_printf(col:%d val:%s\n",column,str);
    }
    else if(G_VALUE_HOLDS_UINT(value)){
        guint n;
        gtk_tree_model_get(model,iter,column,&n,-1);
        g_value_set_uint(value,n);
        g_printf(col:%d n:%u\n",column,n);
    }
}

In your filtermodifyfunc() function you are supposed to set value for the treemodelfilter iter and column based on data in the child treemodel. In your case you need to convert iter to a child iter and then retrieve the value from the child model and then modify it to generate the data to set in value. Also it's usually better to differentiate the value to return based on the column number passed in rather than the type of the value.

Something like the following might work for your example:

void filtermodifyfunc(
                     GtkTreeModel *model,
                     GtkTreeIter *iter,
                     GValue *value,
                     gint column,
                     gpointer data)
{
   g_printf("passed\n");
         if (column == 0) {
             gchar *str;
             GtkTreeIter citer;
             GtkTreeModel *cmodel = gtk_tree_model_filter_get_model(model);
gtk_tree_model_filter_convert_iter_to_child_iter(model, &citer, iter);
              gtk_tree_model_get(cmodel,&citer,column,&str,-1);
              g_value_set_string(value,str);
              g_printf(col:%d val:%s\n",column,str);
         }
         if (column == 1) {
....

John




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]