Re: gtk_list_find() problem



On Thu, Dec 30, 2004 at 11:28:01PM -0500, Tristan Van Berkom wrote:
On Thu, 30 Dec 2004 21:43:50 -0600, David <dbree duo-county com> wrote:
I know I ask some quite elementary questions, but here's another.  I've
pored over this thing and can't find the problem.

Heres the problem:
    offsetpt = gtk_entry_get_text (GTK_ENTRY (GTK_BIN (
                                   data->offset_entry)->child));

offsetpt, you would think would be the same over and over because
the content of the string is the same, but the address of the string is 
different ;-)

Maybe I didn't include enough code to really explain it.  This code is
in a callback function and "offsetpt" is a local variable defined in the
function.  "offsetpt" is used to supply the string for g_string_printf()
to insert into the output string and it is always correct.

Hmm.. wait a minute.. A light just came on!  I'm assuming that what's
contained in the GList is a pointer to the string.  So g_list_find()
is actually comparing the value of what's stored in the list to the
pointer value passed by the 'find' function.  I just tried this in my
test program and when I run 'find' using a g_strdup(els[1]), it
_doesn't_ find it, so that must be the case.

On thinking about it, that's the way it would need to be, but in a way,
it seems to limit the usefulness of the find function.  ATM, it seems
that you'd not usually have the address of a string at hand.  It would
seem that we need a g_list_find_string() function.  Maybe it's not that
common that you do need to run a test like this on a GList, but it seems
that it would be useful.

You could use g_list_find_custom to compare the string
(I wonder if you could get away with just passing `strcmp' as
a compare func ;-).

I'd thought that perhaps this might be necesary, and apparently it will
be for my case.

Thanks for the reply.  Things are much clearer now.




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