Usage of gtk_list_store_set_valuesv()

2012-01-02 Thread Antonio Weber
Hi list,

I'm trying to write a small app which uses a GtkTreeView to display a table. 
For some reason it does not work as expected so I extracted my usage in a small 
tableTest app (which a attach to this mail).
I have 10 columns and 100 rows.

Basically this is the central function:

static void populateTable(GtkTreeView *treeView) {
    int i;
    char data[1024];
    GType types[COLUMN_COUNT];
    GtkTreeViewColumn *column;

    for(i = 0; i  COLUMN_COUNT; i++) {
    sprintf(data, %d, i + 1);
    types[i] = G_TYPE_STRING;
    
    column = gtk_tree_view_column_new_with_attributes(data, 
gtk_cell_renderer_text_new(), text, 0, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW(treeView), column);
    }

    int j;
    GtkTreeIter iter;
    GtkListStore *listStore = gtk_list_store_newv(COLUMN_COUNT, types);

    for(i = 0; i  ROW_COUNT; i++) {
    /*
    GValue values[COLUMN_COUNT];
    gint columnIds[COLUMN_COUNT];
    */

    GValue *values = g_slice_alloc0(sizeof(GValue) * COLUMN_COUNT);
    gint *columnIds = g_slice_alloc0(sizeof(gint) * COLUMN_COUNT);
    
    memset(values, 0x0, sizeof(values));
    
    gtk_list_store_append(listStore, iter);

    for(j = 0; j  COLUMN_COUNT; j++) {
    
    sprintf(data, %d, j + 1);
    printf(Data=%s\n, data);

    g_assert(!G_VALUE_HOLDS_STRING(values[j]));
    g_value_init(values[j], G_TYPE_STRING);
    g_value_set_string(values[j], data);

    columnIds[j] = j;
    }
    gtk_list_store_set_valuesv(listStore, iter, columnIds, values, 
COLUMN_COUNT);
    g_slice_free1(sizeof(GValue) * COLUMN_COUNT, values);
    g_slice_free1(sizeof(gint) * COLUMN_COUNT, columnIds);
    }
    gtk_tree_view_set_model(treeView, GTK_TREE_MODEL(listStore));    
}

I expected that in each row I see
col '1' = '1'  | col '2' = '2' etc...

But In my case each cell holds the value '1'

What do I wrong here?

Thanks a lot,
Antonio

___
SMS schreiben mit WEB.DE FreeMail - einfach, schnell und
kostenguenstig. Jetzt gleich testen! http://f.web.de/?mc=021192
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Usage of gtk_list_store_set_valuesv()

2011-12-10 Thread Antonio Weber
Hi list,

I'm trying to write a small app which uses a GtkTreeView to display a table. 
For some reason it does not work as expected so I extracted my usage in a small 
tableTest app (which a attach to this mail).
I have 10 columns and 100 rows.

Basically this is the central function:

static void populateTable(GtkTreeView *treeView) {
    int i;
    char data[1024];
    GType types[COLUMN_COUNT];
    GtkTreeViewColumn *column;

    for(i = 0; i  COLUMN_COUNT; i++) {
    sprintf(data, %d, i + 1);
    types[i] = G_TYPE_STRING;
    
    column = gtk_tree_view_column_new_with_attributes(data, 
gtk_cell_renderer_text_new(), text, 0, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW(treeView), column);
    }

    int j;
    GtkTreeIter iter;
    GtkListStore *listStore = gtk_list_store_newv(COLUMN_COUNT, types);

    for(i = 0; i  ROW_COUNT; i++) {
    /*
    GValue values[COLUMN_COUNT];
    gint columnIds[COLUMN_COUNT];
    */

    GValue *values = g_slice_alloc0(sizeof(GValue) * COLUMN_COUNT);
    gint *columnIds = g_slice_alloc0(sizeof(gint) * COLUMN_COUNT);
    
    memset(values, 0x0, sizeof(values));
    
    gtk_list_store_append(listStore, iter);

    for(j = 0; j  COLUMN_COUNT; j++) {
    
    sprintf(data, %d, j + 1);
    printf(Data=%s\n, data);

    g_assert(!G_VALUE_HOLDS_STRING(values[j]));
    g_value_init(values[j], G_TYPE_STRING);
    g_value_set_string(values[j], data);

    columnIds[j] = j;
    }
    gtk_list_store_set_valuesv(listStore, iter, columnIds, values, 
COLUMN_COUNT);
    g_slice_free1(sizeof(GValue) * COLUMN_COUNT, values);
    g_slice_free1(sizeof(gint) * COLUMN_COUNT, columnIds);
    }
    gtk_tree_view_set_model(treeView, GTK_TREE_MODEL(listStore));    
}

I expected that in each row I see
col '1' = '1'  | col '2' = '2' etc...

But In my case each cell holds the value '1'

What do I wrong here?

Thanks a lot,
Antonio

___
SMS schreiben mit WEB.DE FreeMail - einfach, schnell und
kostenguenstig. Jetzt gleich testen! http://f.web.de/?mc=021192
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: Usage of gtk_list_store_set_valuesv()

2011-12-10 Thread Antonio Weber
Sorry - really tried to attach a file - my fault :)
Here you can get the tar: 
https://sites.google.com/site/webadone/tableTest.tar.gz[../redirect?goto=https%3A%2F%2Fsites.google.com%2Fsite%2Fwebadone%2FtableTest.tar.gz]

Thanks a lot,
Antonio


-Ursprüngliche Nachricht-
Von: Antonio Weber antonio_we...@web.de
Gesendet: 10.12.2011 20:16:39
An: gtk-app-devel-list@gnome.org
Betreff: Usage of gtk_list_store_set_valuesv()

Hi list,

I'm trying to write a small app which uses a GtkTreeView to display a table. 
For some reason it does not work as expected so I extracted my usage in a 
small tableTest app (which a attach to this mail).
I have 10 columns and 100 rows.

Basically this is the central function:

static void populateTable(GtkTreeView *treeView) {
    int i;
    char data[1024];
    GType types[COLUMN_COUNT];
    GtkTreeViewColumn *column;

    for(i = 0; i  COLUMN_COUNT; i++) {
    sprintf(data, %d, i + 1);
    types[i] = G_TYPE_STRING;
    
    column = gtk_tree_view_column_new_with_attributes(data, 
gtk_cell_renderer_text_new(), text, 0, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW(treeView), column);
    }

    int j;
    GtkTreeIter iter;
    GtkListStore *listStore = gtk_list_store_newv(COLUMN_COUNT, types);

    for(i = 0; i  ROW_COUNT; i++) {
    /*
    GValue values[COLUMN_COUNT];
    gint columnIds[COLUMN_COUNT];
    */

    GValue *values = g_slice_alloc0(sizeof(GValue) * COLUMN_COUNT);
    gint *columnIds = g_slice_alloc0(sizeof(gint) * COLUMN_COUNT);
    
    memset(values, 0x0, sizeof(values));
    
    gtk_list_store_append(listStore, iter);

    for(j = 0; j  COLUMN_COUNT; j++) {
    
    sprintf(data, %d, j + 1);
    printf(Data=%s\n, data);

    g_assert(!G_VALUE_HOLDS_STRING(values[j]));
    g_value_init(values[j], G_TYPE_STRING);
    g_value_set_string(values[j], data);

    columnIds[j] = j;
    }
    gtk_list_store_set_valuesv(listStore, iter, columnIds, values, 
COLUMN_COUNT);
    g_slice_free1(sizeof(GValue) * COLUMN_COUNT, values);
    g_slice_free1(sizeof(gint) * COLUMN_COUNT, columnIds);
    }
    gtk_tree_view_set_model(treeView, GTK_TREE_MODEL(listStore));    
}

I expected that in each row I see
col '1' = '1'  | col '2' = '2' etc...

But In my case each cell holds the value '1'

What do I wrong here?

Thanks a lot,
Antonio

___
SMS schreiben mit WEB.DE FreeMail - einfach, schnell und
kostenguenstig. Jetzt gleich testen! http://f.web.de/?mc=021192


___
SMS schreiben mit WEB.DE FreeMail - einfach, schnell und
kostenguenstig. Jetzt gleich testen! http://f.web.de/?mc=021192
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: Usage of gtk_list_store_set_valuesv()

2011-12-10 Thread David Nečas
On Sat, Dec 10, 2011 at 08:16:39PM +0100, Antonio Weber wrote:
 I'm trying to write a small app which uses a GtkTreeView to display a
 table. For some reason it does not work as expected so I extracted my
 usage in a small tableTest app (which a attach to this mail).

You bind all view columns to model column 0.  So they all display the
data in column 0.  See your gtk_tree_view_column_new_with_attributes().

Yeti

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Usage of gtk_list_store_set_valuesv()

2011-12-10 Thread Antonio Weber
Ah thanks a lot thats it!
Sorry was my fault - should have had a closer look on it.

have a nice weekend,
Antonio


-Ursprüngliche Nachricht-
Von: David Nečas y...@physics.muni.cz
Gesendet: 10.12.2011 20:53:59
An: Antonio Weber antonio_we...@web.de
Betreff: Re: Usage of gtk_list_store_set_valuesv()

On Sat, Dec 10, 2011 at 08:16:39PM +0100, Antonio Weber wrote:
 I'm trying to write a small app which uses a GtkTreeView to display a
 table. For some reason it does not work as expected so I extracted my
 usage in a small tableTest app (which a attach to this mail).

You bind all view columns to model column 0. So they all display the
data in column 0. See your gtk_tree_view_column_new_with_attributes().

Yeti



___
SMS schreiben mit WEB.DE FreeMail - einfach, schnell und
kostenguenstig. Jetzt gleich testen! http://f.web.de/?mc=021192
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list