Re: Fixed: GSignal connect with struct *pointer
- From: Owen Taylor <otaylor redhat com>
- To: Matthias Mann <matman matman24 org>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: Fixed: GSignal connect with struct *pointer
- Date: 10 Aug 2003 17:13:03 -0400
On Sun, 2003-08-10 at 16:12, Matthias Mann wrote:
On Saturday August 09 2003 13:57 CEST, Leandro A. F. Pereira
wrote:
Sure it's possible :)
Thanx to God ore something else. I got an idea and found two
important mistakes in my code. And also a bad discription
about g_signal_connect() in libglib API:
The G_CONNECT_SWAPPED flag is explained with "wether the
instance and data should be swapped when calling the handler".
This is very idiocy. I mean, nobody will get the idea to swap
the instance with the user datas.
I find out: without G_CONNECT_SWAPPED no data will be send to
the callback function. So the API of g_signal_connect() should
start with:
#define g_signal_connect(instance, detailed-signal,
c-handler, NULL);
_NO_ user data. To send user data to a callback function the
only way is to use g_signal_connect_swapped(). That's it! Or
did i oversee any thing?
Just about everything. I'm not sure what you are trying, but
not the right thing...
void
on_clicked1 (GtkButton *button, gpointer data)
{
MyStruct *my_struct = data;
/* Use my_struct */
}
void
on_clicked2 (gpointer data, GtkButton *button)
{
MyStruct *my_struct = data;
/* Use my_struct */
}
g_signal_connect (button1, "clicked",
G_CALLBACK (on_clicked1), my_struct);
g_signal_connect_swapped (button2, "clicked",
G_CALLBACK (on_clicked12), my_struct);
Will work exactly as one might expect. "swapped" is just a
shortcut for reusing an existing function. It generally should
be avoided.
One guess is that you haven't noticed yet that event signals
have different callback signatures than, say, "clicked"
So, it's:
gboolean
on_button_press_event (GtkWidget *widget,
GdkEventButton *event
gpointer data);
For a normal signal connection.
Always look in the docs before using a signal to find the
correct callback signature.
Regards,
Owen
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]