Re: problem with combo box
- From: Thomas Mailund Jensen <mailund daimi aau dk>
- To: gtk-list redhat com
- Subject: Re: problem with combo box
- Date: 08 Aug 1998 18:16:10 +0200
>>>>> "drow" == A Dark Elf <drow@DarkElf.net> writes:
drow> On 8 Aug 1998, Thomas Mailund Jensen wrote:
>> What do you do with link after the append?
>>
>> gtk_text_insert copies the text inserted, printf sends the text to
>> stdout, and couldn't care less what happens afterwards, but
>> g_list_append just inserts the pointer.
>>
>> If you mess around with line after the append, you're probably
>> shooting yourself in the foot...and this could be what happens.
>>
>> If you copy line before you append it, it should work fine...
>>
>> /mailund
drow> Yea I thought about that. The problem is, will I use all diff
drow> variables for every line inserted? even:
drow> strcpy(temp, line);
drow> before the appending doesn't change much the result..
No, but g_strdup (line) might ;)
Take a look at the attached program...run it and type
foo
bar
baz
^D
and marvel at the result :)
/mailund
===File ~/tmp/bar.c=========================================
#include <gtk/gtk.h>
int
main (int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *combo;
GList *cbitems = NULL;
char line[128];
/* initialize */
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
combo = gtk_combo_new ();
gtk_container_add (GTK_CONTAINER (window), combo);
/* get lines for combo */
while (gets (line)) {
cbitems = g_list_append(cbitems, g_strdup (line));
}
gtk_combo_set_popdown_strings (GTK_COMBO (combo), cbitems);
/* show */
gtk_widget_show_all (window);
/* main loop */
gtk_main ();
return 0;
}
============================================================
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]