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


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