Re: Combo append
- From: James Henstridge <james daa com au>
- To: Jano Crema <jano bhquality com br>
- Cc: Devel-Lista-GTK <gtk-devel-list gnome org>
- Subject: Re: Combo append
- Date: Fri, 14 Dec 2001 12:33:45 +0800
This should really have gone to gtk-list gnome org or
gtk-app-devel-list. This list is for discussion about development _of_
gtk, rather than development _with_ gtk.
Jano Crema wrote:
The object receive test1 e test2
glist = g_list_append(glist, "test1");
glist = g_list_append(glist, "test2");
gtk_combo_set_popdown_strings( GTK_COMBO(combo), glist) ;
Why this not works, only appear test2 (two times)
sprintf(empresa, "test1");
glist = g_list_append(glist, empresa);
sprintf(empresa, "test2");
glist = g_list_append(glist, empresa);
gtk_combo_set_popdown_strings( GTK_COMBO(combo), glist) ;
The sprintf calls copy the contents of the string into the buffer
empresa -- they don't create new strings.
So the sequence in your second example is:
put "test1" in empresa.
append the address of empresa to the list
now put "test2" in empresa (this overwrites the last value you set).
append the address of empresa to the list again.
So you get two pointers to empresa in the list, which is why you see
"test2" twice. If you are using format strings, you might be interested
in the g_strdup_printf() function, which is like sprintf, but allocates
the result on the heap.
After calling gtk_combo_set_popdown_strings, don't forget to free the
strings and the list, or you will leak.
James.
--
Email: james daa com au
WWW: http://www.daa.com.au/~james/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]