PDA

View Full Version : Anyone know GTK? annoying me


Guest
November 11th, 2006, 03:19 AM
I wanna get on and actually do something, but I can't figure out what i'm doing wrong.

Basically i'm building a tree view (Just simple text colum of all the compiz plugins).


Fo some reason this doesn't work:


void plugins_loop(gchar * dir) {

GtkTreeIter *iter;
gchar string[100];
strcpy(string, "my string");


/* Append a row and fill in some data */
gtk_list_store_append (store, iter);
gtk_list_store_set (store, iter,
COL_NAME, string,
-1);
}


butthis works fine:


void plugins_loop(gchar * dir) {

GtkTreeIter *iter;

/* Append a row and fill in some data */
gtk_list_store_append (store, iter);
gtk_list_store_set (store, iter,
COL_NAME, "Test",
-1);
}


with the first example the text is not displayed properly and i get Pango-WARNING **: Invalid UTF-8 string passed to pango_layout_set_text(). Anyone know where i'm going wrong?

RYX
November 11th, 2006, 03:40 AM
I cannot exactly say what's wrong but it could be that initializing the string with a length of 100 causes the problem. You could try to set it to the exact length of the string and see what happens. It is some strange unicode-related problem, that stuff is very nasty and I am new to C myself so I can only guess ...

:)

RYX
November 11th, 2006, 03:43 AM
It could also be that strcpy messes up the unicode, but it shouldn't afaik (I think gchar should support unicode automatically but I don't really know) ...

Guest
November 11th, 2006, 03:49 AM
Don't think it's that because this doesn't work either.

void plugins_loop(gchar * dir) {

GtkTreeIter *iter;

gchar * string = g_strdup_printf("%s", "Test");


/* Append a row and fill in some data */
gtk_list_store_append (store, iter);
gtk_list_store_set (store, iter,
COL_NAME, string,
-1);

}


Maybe it's wrong somewhere else, or my locales are screwed up...

Guest
November 11th, 2006, 12:25 PM
found the solution, I forgot to malloc memory to the iter.

GtkTreeIter *iter;
iter = malloc(sizeof(GtkTreeIter));

/* Append a row and fill in some data */
gtk_list_store_append (store, iter);
gtk_list_store_set (store, iter,
COL_NAME, dir_name,
-1);

//Free iter
gtk_tree_iter_free(iter);


Thanks

lowfi
November 11th, 2006, 03:26 PM
the comon way to do this is,
GtkTreeIter iter;
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter, COL_NAME, dir_name, -1);
you don't need to malloc/free.

hope this helps :)