Re: Help: how to disconnect a signal?



Tom Liu wrote:

Is this only way to do so?  What a pain!!
Well; there's got to be a list of attatched handler id's somewhere on the object or that signal or its marshaller or something; but some of the attatched handlers
might not be desireable to remove
i.e. "child widget wants to know when parent container gets resized"
or the object's handler itself.

AFAIK there is no "pool of private handlers" and "pool of user handlers" but maybe.

Regards,
                           -Tristan

Also I have to free glist when widget got destroyed to avoid memory
leak:

g_object_set_data_full(G_OBJECT(obj), "handler_list", l,g_list_free);
thanks!



-----Original Message-----
From: gtk-app-devel-list-admin gnome org
[mailto:gtk-app-devel-list-admin gnome org] On Behalf Of Tristan Van
Berkom
Sent: Thursday, November 20, 2003 10:51 AM
To: Tom Liu
Cc: 'Tim Müller'; gtk-app-devel-list gnome org
Subject: Re: Help: how to disconnect a signal?

/*********************
 CODE TO CONNECT
*********************/
gint sig_id = g_signal_connect(G_OBJECT(obj));
GList *l = NULL;

/* first time NULL */
l = g_object_get_data(G_OBJECT(obj), "handler_list");
l = g_list_append(l, sig_id);
g_object_set_data(G_OBJECT(obj), "handler_list", l);
 /***************************************
 CODE TO DISCONNECT ALL HANDLERS
 ***************************************/
GList *list = g_object_get_data(G_OBJECT(obj), "handler_list");
GList *l = list;
while (l) {
   g_signal_handler_disconnect(G_OBJECT(obj), (gint )l->data);
   l = l->next;
}
list = (g_list_free(list), NULL);
g_object_set_data(G_OBJECT(obj), "handler_list", NULL);

Cheers,
                   -Tristan




Tom Liu wrote:

I didn't record the id of the signal and don't know how many functions
conneted. I just want to disconnect all the connected functions.

The thing I need this is I am porting the Motif to GTK.
In the old program, I have a pice of code like:
        Widget widg;
        XtRemoveAllCallbacks(widg, XmNmodifyVerifyCallback);
        XtRemoveAllCallbacks(widg, XmNactivateCallback);

Thanks.



-----Original Message-----
From: gtk-app-devel-list-admin gnome org
[mailto:gtk-app-devel-list-admin gnome org] On Behalf Of Tim Müller
Sent: Thursday, November 20, 2003 4:55 AM
To: gtk-app-devel-list gnome org
Subject: Re: Help: how to disconnect a signal?

On Wednesday 19 November 2003 22:23, Tom Liu wrote:



I want to disconnect all the "clicked" signal from a button. I spend
an


hour already, don't know how to use the function

g_signal_handlers_disconnect_matched

I tried: g_object_disconnect (G_OBJECT(w),"clicked") also. Doesn't
work.

gulong id;

id = g_signal_connect(button, "clicked", G_CALLBACK(onButtonClicked),
NULL);

g_signal_handler_disconnect(button, id);


or:

g_signal_connect(button, "clicked", G_CALLBACK(onButtonClicked), NULL);

g_signal_handlers_disconnect_by_func(button, onButtonClicked, NULL);


See http://developer.gnome.org/doc/API/2.0/gobject/gobject-Signals.html

Cheers
-Tim




_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list




--
"A line of code is worth a thousand words"
   -me

_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list







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