Re: gtk_widget_destroy on dialog freezes application
- From: John Cupitt <john cupitt ng-london org uk>
- To: Mattias Persson <matte_gtk hotmail com>
- Cc: gtk-list gnome org
- Subject: Re: gtk_widget_destroy on dialog freezes application
- Date: Thu, 02 Aug 2001 11:22:46 +0100
Hi Mattias,
Mattias Persson wrote:
> From my top-level window i create a dialog window by
> clicking a button:
>
> gtk_signal_connect(GTK_OBJECT(dia_button), "released",
> GTK_SIGNAL_FUNC(clicked_button),
> NULL);
>
> void clicked_button(GtkButton* butt, gpointer data){
> GtkWidget* dialog;
> dialog = create_dialog();
> gtk_widget_show(dialog);
> }
>
> This dialog has a close button which is supposed to
> close the dialog:
>
> gtk_signal_connect(GTK_OBJECT(close_button), "released",
> GTK_SIGNAL_FUNC(kill_dialog), myself);
>
> where myself is the dialog itself.
>
> int kill_dialog(GtkButton* butt, gpointer data){
> gtk_widget_destroy(GTK_WIDGET(data));
> return TRUE;
> }
>
> Now to my problem: When i try to close the dialog window
> everything freezes. I can still move the windows
> around, but they do not respond to input and are not
> redrawn. I've tried to change gtk_widget_destroy with
> gtk_widget_hide and that works just fine but it's
> rather ugly.
I'm not sure what's wrong ... you should really connect to "clicked", not
"released", but I think this should work anyway. Maybe you have a bug somewhere
else?
Here's a test program:
--
#include <gtk/gtk.h>
static void
button_clicked( GtkWidget *button, GtkWidget *widget )
{
gtk_widget_destroy( widget );
}
int
main( int argc, char **argv )
{
GtkWidget *window;
GtkWidget *button;
gtk_set_locale();
gtk_init( &argc, &argv );
window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
button = gtk_button_new_with_label( "click me" );
gtk_container_add( GTK_CONTAINER( window ), button );
gtk_signal_connect( GTK_OBJECT( button ), "clicked",
GTK_SIGNAL_FUNC( button_clicked ), window );
gtk_widget_show_all( window );
gtk_main();
return( 0 );
}
--
This works for me. Does this help?
You can make this a bit simpler: gtk_signal_connect_object() lets you call a
function with an argument. You can remove the button_clicked() function, and
instead write:
gtk_signal_connect_object( GTK_OBJECT( button ), "clicked",
GTK_SIGNAL_FUNC( gtk_widget_destroy ), window );
This only works for trivial dialogs though, you usually need to write a dialog
close function.
John
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]