Re: Data to Callback Functions
- From: Ruben Safir Secretary NYLXS <ruben mrbrklyn com>
- To: Sven Neumann <sven gimp org>
- Cc: Ruben Safir Secretary NYLXS <ruben mrbrklyn com>, gtk-list gnome org
- Subject: Re: Data to Callback Functions
- Date: Mon, 23 Aug 2004 05:16:45 -0400
I think your right, and I was on IRC for a bit tonight fishing for answers.
I'm calling for an instance of the structure on the stack and forgetting
that the entire stack vanishes when the program returns to gtk_main.
This makes the usefulness of gpointer data in the callback function a lot
less usefull than I'd like. It seems that literal data like a string
gets sent, and GtkWidget objects can be sent, but other kinds of
data, such as my struct, doesn't get passed to the callback function
because it doesn't get caputers by gtk_main and it falls off the stack.
I'm going to try to envelope the struct in g_new and see if that works.
Otherwise, I'll declare the entire struct instance in main and make it
globally available.
Thanks for taking the time to help a green horn.
Ruben
On Mon, Aug 23, 2004 at 10:39:18AM +0200, Sven Neumann wrote:
> Hi,
>
> Ruben Safir Secretary NYLXS <ruben mrbrklyn com> writes:
>
> > I'm trying to write a program for the clinical pharmacy department
> > at the hospital. I hoped to create a top_level window with a vbox.
> > The top of the vbox has some buttons and the bottom has a frame.
> > Depending on which button is clicked, a different 'form' would
> > desplay below.
> >
> > In order to do this I created several files, clinical.c clinical.h
> > forms.c forms.h calculations.c calculations.h, so I could use the
> > calculations for a future project.
> >
> > In order to retain access to everything, in fomrs.h I has a struct
> > definition struc s1, which has membership of GtkWidgets which I
> > hoped to assign to structure instances to pass to callback functions
> > attacts as gpoint data, with is the last argument in
> > g_signal_connect, such as follows
> >
> > g_signal_connect (G_OBJECT (button), "clicked",
> > G_CALLBACK (lbw_screen), &handle);
> >
> > where handle is my structure with the GtkWidgets stored.
>
> It should work that way but unless you show us some more code we
> cannot help you to find out why it doesn't work for you. My guess is
> that the handle struct is stack-allocated memory at the time you
> connect the callback and doesn't exist any longer when the signal is
> run. But w/o seeing more code that's just a guess.
>
>
> Sven
--
__________________________
Brooklyn Linux Solutions
So many immigrant groups have swept through our town
that Brooklyn, like Atlantis, reaches mythological
proportions in the mind of the world - RI Safir 1998
DRM is THEFT - We are the STAKEHOLDERS - RI Safir 2002
http://fairuse.nylxs.com
http://www.mrbrklyn.com - Consulting
http://www.inns.net <-- Happy Clients
http://www.nylxs.com - Leadership Development in Free Software
http://www2.mrbrklyn.com/resources - Unpublished Archive or stories and articles from around the net
http://www2.mrbrklyn.com/downtown.html - See the New Downtown Brooklyn....
1-718-382-0585
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]