Re: [gtk-list] Re: Signal data value ?
- From: "Timothy I. McGinnis" <tmcginnis synertechsystems com>
- To: gtk-list redhat com
- Subject: Re: [gtk-list] Re: Signal data value ?
- Date: Fri, 17 Sep 1999 15:13:13 -0500
Thanks for the info on the pathetic state of my code. I will definitely
take a look at the comp.lang.c FAQ, and what is a good C book? I've been
through the book by Kernighan and Ritchie (original printing, its been a
while) and obviously missed some things.
Upon further investigation and some reading of Havoc Pennington's online
GGAD I figured out the problem was my use of the incorrect
gtk_signal_connect(). Instead of using "clicked" I was using
"focus_out_event" and I was only expecting two arguments in the callback
function. After I started looking for the correct number of arguments in
my callback function then everything turned out correctly.
Thanks,
Tim M.
Erik Mouw <J.A.K.Mouw@its.tudelft.nl> on 09/17/99 01:01:49 PM
Please respond to gtk-list@redhat.com
To: gtk-list@redhat.com
cc:
bcc:
Subject: [gtk-list] Re: Signal data value ?
On Fri, 17 Sep 1999 09:02:55 -0500, Timothy I. McGinnis wrote:
> I am having problems trying to get a data value from a signal. I have a
> gchar pointer which when I connect up the signal has the value 134685549,
> but when I check the data value in the callback function I get a entirely
> different value, -1073751463.
> And I can't access the correct data. What am I doing wrong?
You're messing with pointers.
> gchar *str;
>
> str = g_malloc0(100);
>
> printf("str=%d\n",str);
You're trying to print the address of an array of characters as if it is
just an integer. If this is really what you want, you'd better make it
explicitly clear with some typecasts.
> gtk_signal_connect( GTK_OBJECT(button), "clicked",
> GTK_SIGNAL_FUNC(display_msg), str);
This is correct.
> display_msg( GtkWidget *widget, gpointer data)
> {
> printf("data=%d\n",data);
> }
Again: you're trying to print the wrong thing.
This should work:
/* allocate memory */
gchar *str = g_malloc0(100);
/* initialize memory */
strcpy(str, "Hello, world!");
printf("address = %p, value = '%s'\n", str, str);
gtk_signal_connect(GTK_OBJECT(button), "clicked",
GTK_SIGNAL_FUNC(display_msg), str);
display_msg(GtkWidget *widget, gpointer data)
{
printf("address = %p, value = '%s'\n", (char *)data, (char *)data);
}
If you're using gcc, you should compile with all warnings on (-Wall) so
the compiler will warn you about coding errors.
I suggest to read a good C book, especially the part that deals with
pointers. The comp.lang.c FAQ is also worth reading (available at
ftp://rtfm.mit.edu/).
Erik
--
J.A.K. (Erik) Mouw, Information and Communication Theory Group, Department
of Electrical Engineering, Faculty of Information Technology and Systems,
Delft University of Technology, PO BOX 5031, 2600 GA Delft, The
Netherlands
Phone: +31-15-2785859 Fax: +31-15-2781843 Email J.A.K.Mouw@its.tudelft.nl
WWW: http://www-ict.its.tudelft.nl/~erik/
--
To unsubscribe: mail -s unsubscribe gtk-list-request@redhat.com < /dev/null
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]