gtk_signal_handler_block: core dump
- From: "Dr. Andrew L. Blais" <onlymice noho com>
- To: gtk <gtk-list gnome org>
- Subject: gtk_signal_handler_block: core dump
- Date: Wed, 14 Mar 2001 01:21:05 -0500
I'm trying to learn gtk. So, I'm trying to modify helloworld2 so that it
has three buttons. The first will gprint "TEST", the second will turn
the first button off, and the third will turn the first back on. Just an
exercise:) I've got this far, but although this code compiles, it core
dumps when I push the second button. I searched the archives, but no
clue. Could please someone explain what is happening here?
Doc Alb
----------------------------------------------------------------
#include <gtk/gtk.h>
void test( GtkWidget *widget, gpointer data )
{ g_print( "%s\n", ( char * ) data ) ; }
struct kill_data { GtkWidget *b ; gint id ; } ;
void kill( struct kill_data *kd )
{
gtk_signal_handler_block( GTK_OBJECT( kd->b ), (guint) kd->id ) ;
}
void live( GtkWidget *widget, gpointer data )
{ g_print( "%s\n", ( char * ) data ) ; }
gint delete_event( GtkWidget *widget, GdkEvent *event, gpointer data )
{ gtk_main_quit( ) ; return( FALSE ) ; }
int main( int argc, char *argv[] )
{
GtkWidget *window ;
GtkWidget *box ;
GtkWidget *button1 ;
GtkWidget *button2 ;
GtkWidget *button3 ;
gint hid ;
struct kill_data *s ;
s = ( struct kill_data* ) malloc( sizeof( struct kill_data ) ) ;
gtk_init( &argc, &argv ) ;
window = gtk_window_new( GTK_WINDOW_TOPLEVEL ) ;
gtk_container_set_border_width( GTK_CONTAINER( window ), 25 ) ;
gtk_window_set_title( GTK_WINDOW( window ), "Button Stuff" ) ;
box = gtk_hbox_new( FALSE, 0 ) ;
button1 = gtk_button_new_with_label( " TEST " ) ;
button2 = gtk_button_new_with_label( " KILL " ) ;
button3 = gtk_button_new_with_label( " LIVE " ) ;
gtk_signal_connect( GTK_OBJECT( window ), "delete_event",
GTK_SIGNAL_FUNC( delete_event ), NULL ) ;
hid = gtk_signal_connect( GTK_OBJECT( button1 ), "clicked",
GTK_SIGNAL_FUNC( test ), ( gpointer ) "TEST" ) ;
s->b = button1 ; s->id = hid ;
gtk_signal_connect( GTK_OBJECT( button2 ), "clicked", GTK_SIGNAL_FUNC(
kill ), s ) ;
gtk_signal_connect( GTK_OBJECT( button3 ), "clicked", GTK_SIGNAL_FUNC(
live ), ( gpointer ) "LIVE" ) ;
gtk_container_add( GTK_CONTAINER( window ), box ) ;
gtk_box_pack_start( GTK_BOX( box ), button1, TRUE, TRUE, 0 ) ;
gtk_box_pack_start( GTK_BOX( box ), button2, TRUE, TRUE, 0 ) ;
gtk_box_pack_start( GTK_BOX( box ), button3, TRUE, TRUE, 0 ) ;
gtk_widget_show( box ) ;
gtk_widget_show( button1 ) ;
gtk_widget_show( button2 ) ;
gtk_widget_show( button3 ) ;
gtk_widget_show( window ) ;
gtk_main( ) ;
return( 0 ) ;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]