Still probs with connecting 2 signals



Now I've got gtk---0.8.3, but still connecting 2 Motion_notify_event's doesn't
work properly. I've attached a testprogram that compiles properly(for me),
but crashes misteriously when pressing the first button, which is connected
to the second one by the button_press_event.  

gdb says:
Program received signal SIGBUS, Bus error.

0x804cda5 in Concretegtkslot1<int, Signal_proxy1<int, Gtk_Widget,
_GdkEventButton *> &, _GdkEventButton *>::callback (p=Cannot access memory at
address 0xd.) at /usr/local/include/gtk--sig.h:982

A stack trace doesn't work, it can't adress the memory.
Pretty awkward :-(

BTW: Maybe it is because I still use gcc 2.7.2, no idea

Bye,
   Oliver
/* This is -*- C++ -*-  */
#include <gtk--.h>

//
// A test for connecting 2 _event signals, e.g. to connect rulers to drawing
// area


class MyDraw : public Gtk_DrawingArea {

public: 
MyDraw();
gint expose_cb(GdkEventExpose *) { 
	GtkWidget *widget;    
	printf("Ouch...I'm exposed!\n"); 
    	widget = GTK_WIDGET(gtkobject);
	gdk_draw_rectangle(widget->window,
                            widget->style->white_gc,
                            TRUE,
                            0, 0,
                            widget->allocation.width,
                            widget->allocation.height);
	return 0;
  }
gint button_press_cb(GdkEventButton *) { 
    printf("Ouch...pressed!\n"); 
    return 0;
  }
gint motion_notify_cb(GdkEventMotion *) { 
  //printf("Ouch...moved!\n");
    return 0; 
  }
/*gint button_press_cb2(GdkEventButton *) { 
    printf("Ouch...callback 2!\n"); 
    return 0;
  }*/  

};
MyDraw::MyDraw(){
  printf("set_events\n");
  set_events(GDK_EXPOSURE_MASK         
           | GDK_BUTTON_PRESS_MASK
           | GDK_POINTER_MOTION_MASK
           | GDK_POINTER_MOTION_HINT_MASK);
	connect(expose_event,this,&expose_cb);
	connect(button_press_event,this,&button_press_cb);
        connect(motion_notify_event,this,&motion_notify_cb);
     //   connect(button_press_event,this,&button_press_cb2);
}




class HelloWorld : public Gtk_Window { // (1) 
  Gtk_Button b1,b2,b3;
  Gtk_HBox hbox;
  Gtk_VBox vbox;

  Gtk_Table table;
  Gtk_HRuler hruler;
  Gtk_VRuler vruler;
  MyDraw drw_area;
  void 	click_cb(int num){printf("Button %d clicked \n",num);};  
public:
  HelloWorld();
  gint ruler_motion_notify(GdkEventMotion *event)
  { 
    typedef gint (*MotionEventFunc)  (GtkWidget *,GdkEventMotion *);  
    GtkWidget *widget = GTK_WIDGET(hruler.gtkobject);  
    MotionEventFunc func =( MotionEventFunc)   (GTK_WIDGET_CLASS(GTK_OBJECT (wid
get)->klass)->motion_notify_event);
 

    func((GtkWidget *)widget,event);
    widget = GTK_WIDGET(vruler.gtkobject);
    func =( MotionEventFunc)   (GTK_WIDGET_CLASS(GTK_OBJECT (widget)->klass)->mo
tion_notify_event);
    func((GtkWidget *)widget,event);


  }

  gint delete_event_impl(GdkEventAny *) {
    printf("Ouch...I'm shot....Aahh!\n"); 
    Gtk_Main::instance()->quit(); 
    return 0;
  }
  
};

HelloWorld::HelloWorld():
    b1("Oh no!"),b2("hi!"),b3("Some text"),
    hbox(false,0),vbox(true,0),table(2,2,false)
  {
    border_width(10);
    drw_area.set_usize(100,100);
    hbox.pack_start(&table);
    hruler.set_range(5,15,0,20);
    vruler.set_range(5,15,0,20);
    table.attach(&hruler,1,2,0,1,GTK_FILL|GTK_EXPAND,GTK_FILL,0,0);
    table.attach(&vruler,0,1,1,2,GTK_FILL,GTK_FILL|GTK_EXPAND,0,0);
    table.attach(&drw_area,1,2,1,2,GTK_FILL|GTK_EXPAND,GTK_FILL|GTK_EXPAND,0,0);

    vbox.pack_start(&b1);
    vbox.pack_start(&b2);
    vbox.pack_start( &b3);  
    hbox.pack_start(&vbox);
  
    //connect( b.clicked, Gtk_Main::instance(), &Gtk_Main::quit );
    connect( b1.clicked,this , &click_cb,1);
    connect( b2.clicked,this , &click_cb,2);
    // connect(b1.clicked,b3.clicked);  //works
    connect(b1.button_press_event,b3.button_press_event);//sigsegv's
     //connect(drw_area.motion_notify_event,hruler.motion_notify_event);
     //connect(drw_area.motion_notify_event,vruler.motion_notify_event);
    //both above crash
     //connect(drw_area.motion_notify_event,this,&ruler_motion_notify);
    //my ruler workaround...
    b3.show();
    b1.show();
    b2.show();
    hruler.show();
    vruler.show();
    table.show();
    drw_area.show();
    vbox.show(); 
    hbox.show();
    add(&hbox); 
  }

int main( int argc, char **argv )
{
  Gtk_Main m( &argc, &argv ); 
  HelloWorld w; 
  
  //w.set_usize( 100,20 ); 
  w.show();
  
  m.run(); 
  return 0;
}














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