Re: g_list_append help!



I am developing an interactive GUI database using Glade and getting 
stuck with glist.
Anybody knows how to supply parameter to g_list_append by a string 
variable instead
of a physical string?  In particular, instead of the following line:

combo2_items = g_list_append (combo2_items, (gpointer) _("blue"));

I want to use:
combo2_items = g_list_append (combo2_items, (gpointer) _(entry_name));

where entry_name is a string variable.  I tried this and what appeared 
in combo2_items was
not the string represented by entry_name, but some weird characters???  

Firstly you don't want to translate it:
        c2items = g_list_append(c2items, entry_name);

Otherwise what is the scope of entry name?  Is a malloced array?  Is it
being reused?  My best guess would be that entry_name is allocated on
the stack and you returning from the function meaning the value of the
string is beign trashed.

To test this try strduping what you add to the list (watch for future
memory leaks):
        c2items = g_list_append(c2items, g_strdup(entry_name));

Note moving from a (char *) to a (void */gpointer) doesn't really need a
cast (unless a gpointer is not a void * on some platform).

        nash
-- 
Brett Nash <nash nash nu>
Sometimes it's better to light a flamethrower than curse the darkness.



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