Re: galde & gtk question



On Mon, May 26, 2003 at 08:14:25AM -0400, Rajarshi Guha wrote:

In some of my callbacks I need to pass a string constant as the last
parameter to g_signal_connect() so that the callback will recieve it as
user_data. Using libglade's glade_xml_signal_autoconnect() to process
the UI file doesnt give me a chance to set this when the signal is
connected to the UI element. 

[...]

Is there any easy way to add user data to a callback using Glade and
libglade (apart from setting individual callbacks by hand) ?

If the widget itself is passed, you could use the widget name as a key, if
that's what you need.

I know it sounds pretty hackish (and a waste of some memory), but one way
that comes to mind is to stick a label with some default text in a
nonvisible window and then use the label name in the "object" field.  Then
retrieve the text with get_text.

It would help to know why you need to pass the string.  If you need to act
based on some key value, It might make sense to have a different callback
for each widget, and have each callback call a function with the shared
functionality:

void foo(char *key) {
     ...
}

void callback_a(...) {
     foo("a");
}

void callback_b(...)  {
     foo("b");
}

Not elegant, but glade at least generates the stubs for you.

Dave Cook



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