Re: [gtk-list] Signal data value ?
- From: Erik Mouw <J A K Mouw its tudelft nl>
- To: gtk-list redhat com
- Subject: Re: [gtk-list] Signal data value ?
- Date: Fri, 17 Sep 99 20:01:49 +0200
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/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]