Gtk-- connect() woes (was Re: gtk-- information ??)




In response to Dave/Landshark's recent postings about having trouble with
gtk-- signals, I decided to write a bit of sample code that would show
him the use of the various forms of connect().

I was able to connect() to callbacks of all three types (member functions,
function objects and regular functions) in the case of signals that didn't
pass any arguments to the callbacks (for example the clicked() signal
associated with a Gtk_Button).

I was not able, however, to get signals whose callbacks take arguments to
work properly.  I took the following code snippet:

#include <gtk--.h>

void button_press_callback_fn(GdkEventButton* b) {
  cout << "You pressed mouse button " << b->button << "\n";
}

main(int argc, char* argv[])
{
  Gtk_Main gtkmain(&argc, &argv);

  Gtk_Window main_window;
	
  Gtk_EventBox ebox();
  ebox.show();
  main_window.add( &ebox );

  connect(ebox.button_press_event, button_press_callback_fn);

  main_window.show();
  gtkmain.run();
}

But when I tried to compile it, I got one of those wonderfully unreadable
compiler messages about templates.  Here it is, reformatted for legibility:

no matching function for call to 
`connect (Signal_proxy1<int,Gtk_Widget,_GdkEventButton *> &,
          void ()(_GdkEventButton *))'

/usr/local/include/gtk--sig.h:735:
candidates are:
connect(Signal0 &, void (*)())

/usr/local/include/gtk--sig.h:1172:
connect<int, Gtk_Widget, void ()(_GdkEventButton *), _GdkEventButton *>
(Signal_proxy1<int,Gtk_Widget,_GdkEventButton *> &,
void ( &)(_GdkEventButton *))

I tried looking at gtk--sig.h line 1172, but it seems to involve
macro-expansion magic and I ran screaming in the other direction...

But notice what it is suggesting as a match: a connect() whose second arg
is a void ( &)(_GdkEventButton *)).  If I'm not mistaken, isn't that
a *reference* to a void function taking a _GdkEventButton* as an argument?

egcs 1.0.1 complains when I try to define 
void ( &funrec )(_GdkEventButton *);
in my code, saying: "cannot declare references to functions; use pointer to
function instead"

And there is certainly no mention that I can find of references to functions
in the latest edition of Stroustrup.

What's up?

-Jon Trowbridge
 EMC Capital Management



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