Re: gtk_combo



On 2001.12.08 21:59 Rafeeq C E  wrote:
Hi,
i declared a string variable(const gchar
value[70]) and copied value read from mysql to
variable and added the string variable to list
using g_list_append (items, value);. It is
working. But the combo box contains only the
last value repeated as many as the number of
records fetched. Is it because of that GList
keeps lvalue of the added string.  Can you
please suggest a work around for this problem. 

Why can't we add some other functions to add
strings to the combo box like in the case of
option menus in gtk2.0 at least.


Then that implies that the mysql function call is returning
the same string value.

GTK uses GLists quite often, it may be good or bad depending
on the individual. But GTK uses GLists quite often so its
important to understand them.

If you have a function that returns a different string on
each call, then you'll want to do it like this:

const gchar *cstrptr;
GList *glist = NULL;

cstrptr = mysql_get_string(handle);
while(cstrptr != NULL)
{
 glist = g_list_append(glist, g_strdup(cstrptr));
 cstrptr = mysql_get_string(handle);
}

/* Now add the glist to the combo box here, the GtkCombo makes a copy
 * of the list internally so its no longer needed after this call.
 */
gtk_combo_set_popdown_strings(combo, glist);

/* Don't forget to deallocate the glist! */
g_list_foreach(glist, (GFunc)g_free, NULL);
g_list_free(glist);
glist = NULL;


--
Sincerely,                  ,"-_                         \|/
-Capt. Taura M.             ,   O=__                    --X--
..__                         ,_JNMNNEO=_                 /|\
OMNOUMmnne.                  {OMMNNNEEEEOO=_
UOOOBIOOOEOMMn.               'LONMMMMNNEEEOOO=.__..,,..
UUOOEUUOOOOOOOObe              '"=OMMMMWNEEEOOOOO,"=OEEEOO=,._
OOUUUIEEIOONNOIUbe.                "7OMMMMNNNNNWWEEEEOOOOOO"   "'.
EEBNNMMMNWNWWEEIMMNe.             __  7EMMMNNNNNWWWEEEEEEEOO.     " .
NNMMMMWWWMMMWEINMMMNn            "=BBEEEEMMMMMMMMNNNWWWEEOOOOO=._     .
                  http://furry.ao.net/~learfox/



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