Re: data in g_signal_connect
- From: <olafandjasper hushmail com>
- To: john cupitt ng-london org uk, olexiy irtech cn ua
- Cc: glade-users lists ximian com, gtk-list gnome org
- Subject: Re: data in g_signal_connect
- Date: Thu, 13 Nov 2003 11:00:51 -0800
Thank you all very much...Both of your posts helped... John I un-globalized
and Olexiy used the correct API/proto.
O
On Thu, 13 Nov 2003 08:31:23 -0800 John Cupitt <john cupitt ng-london org uk>
wrote:
>Hi, you're creating an instance of MY_DATA in the header file, then
>including that header in two places. So you're getting two versions
>of MY_DATA. You should never make variables in headers, only declare
>that they exist elsewhere (with an extern).
>
>Remove the line "struct MY_DATA mydata;" from the header, and remove
>the "extern" from the declaration in SQLstuff.c.
>
>In any case, it's probably not wise to use globals like this. It's
>better to g_new( MY_DATA ) to allocate a new one off the heap, and
>then make sure you g_free() it somewhere sensible.
>
>HTH,
>
>John
>
>olafandjasper hushmail com wrote:
>> Hello again:
>> This is a follow-up of a previous thread I started in early Nov.
>> I appreciate the help I got from the list, but I am still having
>difficulty.
>> Someone suggested I use a different prototype, but I got the same
>(wrong)results:
>> void slectActionBin (GtkWidget *widget,
>> GdkEvenButton *event,
>> MY_DATA *data)
>>
>> The problem is the data is not being printed out in the callback
>routine.
>> You can see, at the bottom of this post, that there is
>> nothing in data and the address is diff :(
>>
>> Can someone help get my data so it is visable/correct in the called
>cb
>> routine.
>> I think (maybe) I am not casting it properly or something, but
>when I
>> called the callback routine directly (commented out the g_connect_signal)
>> the data was correct....hmmmm
>>
>> Here is the code that does not work:
>> =========================================================
>> mySupport.h:
>> struct MY_DATA {
>> char bin[1000];
>> char doc[1000];
>> };
>>
>
>>
>> struct MY_DATA mydata;
>>
>> =========================================================
>> mySupport.c:
>> void selectActionBin(GtkWidget *button,
>> struct MY_DATA *data)
>> {
>> /* This is the code that does not work */
>> printf("In call back, data = <%s>\n",data->bin);
>> printf("In call back, data = <%s>\n",data->doc);
>> printf("In call back, data is at %p\n", data);
>> printf("In call back, &data is at %p\n", &data);
>> }
>> =========================================================
>> SQLstuff.c:
>> -- This is where I set up my callback/data
>> extern struct MY_DATA mydata;
>> int doQuery(char *sqlStr)
>> {
>> strcpy(mydata.bin,"Test data");
>> strcpy(mydata.doc,"Test data");
>> printf("Data is <%s> before callback\n",mydata.bin);
>> printf("Data is <%s> before callback\n", mydata.doc);
>> printf("Data is at %p before callback\n", mydata);
>> printf(" &data is at %p before callback\n", &mydata);
>> g_signal_connect(G_OBJECT (butWidget),
>> "button_press_event",
>> G_CALLBACK (selectActionBin),
>> &mydata);
>> }
>> =========================================================
>> output: (as you can see the callback is called but nothing is
>> in the data and the address are diff) :(
>>
>> Data is <Test data> before callback
>> Data is <Test data> before callback
>> Data is at 0x74736554 before callback
>> &data is at 0x80513a0 before callback
>>
>> In call back, data = <>
>> In call back, data = <>
>> In call back, data is at 0x8a3e6e0
>> In call back, &data is at 0xbfffd944
>>
>>
>> Thanks,
>> O
>>
>>
>>
>>
>> Concerned about your privacy? Follow this link to get
>> FREE encrypted email: https://www.hushmail.com/?l=2
>>
>> Free, ultra-private instant messaging with Hush Messenger
>> https://www.hushmail.com/services.php?subloc=messenger&l=434
>>
>> Promote security and make money with the Hushmail Affiliate Program:
>>
>> https://www.hushmail.com/about.php?subloc=affiliate&l=427
>> _______________________________________________
>> gtk-list mailing list
>> gtk-list gnome org
>> http://mail.gnome.org/mailman/listinfo/gtk-list
>>
>
>
>
Concerned about your privacy? Follow this link to get
FREE encrypted email: https://www.hushmail.com/?l=2
Free, ultra-private instant messaging with Hush Messenger
https://www.hushmail.com/services.php?subloc=messenger&l=434
Promote security and make money with the Hushmail Affiliate Program:
https://www.hushmail.com/about.php?subloc=affiliate&l=427
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]