Re: [gtk-list] Re: gtk-- listitem/button-press signal question




> >   int onButtonPress(gint i, Gtk_Widget w,GdkEventButton* evt) {
> >      // Check event type to see if it was a double click
> >   }
> >      connect( item1->button_press_event, *this,

afo@tesis.de (Andre Fornacon) writes:
> 	void ListCB(GdkEventButton *);
> 
> 	_list=new Gtk_List();
> 	connect(_list,"button_press_event",this,ListCB);

You both have it wrong. This is exactly the reason there's static
typechecking in gtk--. The connect() which Andre used is obsolete and
will be removed in the future as it provides NO typechecking. Please
dont use it.

in gtk--gen.h has the following definition:
SIGNAL_SPEC(gint button_press_event(GdkEventButton*));

and thus the callback should be in form(this is inside class derived from some 
gtk-- widget):

gint Onbuttoncallback(GdkEventButton* e) { ... }

...
Gtk_Widget *obj=new some_gtk_widget;
connect(obj->button_press_event, this, &Onbuttoncallback);

Note that this checks the argument types for both the signal and the
method you're using. If you have problems with return types or
argument types, it'll give type unification error(or something else to
do with template instantiation) at compile time. (you both had the
method signature wrong, but Andre just skipped the type checking)

check the connect method signatures from web page.

Tho I usually use the *_event methods by overriding the virtual method -
as it is easier(this is inside class derived from Any Gtk_Widget):
 class Mybutton : public Gtk_Button {
 public:
  gint button_press_event_impl(GdkEventButton* e) { ... Gtk_Button::button_press_event_impl(e); ... }
 };

-- 
-- Tero Pulkkinen -- terop@modeemi.cs.tut.fi --



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