Re: gtk_tree_model_filter_set_modify_func()
- From: Russell Shaw <rjshaw netspace net au>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: gtk_tree_model_filter_set_modify_func()
- Date: Thu, 01 Jul 2004 03:19:32 +1000
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);
}
}
----------------------------------------------------------------------
Program:
#include <stdlib.h>
#include <stdio.h>
#include <gtk/gtk.h>
#include <gtk/gtksignal.h>
#include <string.h>
static
gboolean delete(
GtkWidget *widget,
GtkWidget *event,
gpointer data)
{
gtk_main_quit ();
}
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);
}
}
gint main(gint argc, gchar *argv[])
{
gtk_init (&argc, &argv);
GtkWidget *window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_signal_connect(G_OBJECT(window),"delete_event",G_CALLBACK(delete),NULL);
GtkListStore *store=gtk_list_store_new(2,G_TYPE_UINT,G_TYPE_STRING);
GtkTreeIter iter;
gtk_list_store_append(store,&iter);
gtk_list_store_set(store,&iter,0,0,1,"abc",-1);
gtk_list_store_append(store,&iter);
gtk_list_store_set(store,&iter,0,1,1,"def",-1);
gtk_list_store_append(store,&iter);
gtk_list_store_set(store,&iter,0,2,1,"ghi",-1);
GtkTreeModel *modelfilter=
gtk_tree_model_filter_new(GTK_TREE_MODEL(store),NULL);
GType types[]={G_TYPE_UINT,G_TYPE_STRING};
gtk_tree_model_filter_set_modify_func(
GTK_TREE_MODEL_FILTER(modelfilter),
2,
types,
filtermodifyfunc,
NULL,
NULL);
gtk_tree_model_get_iter_first(GTK_TREE_MODEL(modelfilter),&iter);
guint n;
gchar *str1;
gtk_tree_model_get(GTK_TREE_MODEL(modelfilter),&iter,0,&n,1,&str1,-1);
g_printf("n:%d val:%s\n",n,str1);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]