Re: connect_notify()



Am 07.03.2005 11:35:55 schrieb(en) Matthias Kaeppler:
Hello,

I want a context menu to popup when the user right-clicks on a tree
view. So I looked up signal_button_press_event() and I was told to
either derive my own view from TreeView (I don't want that) and
override
the default handler, or use connect_notify() instead.
Well, what does this mysterious function do? Googling for it turned
out
that it has something to do with coverting non-void return types to
void
return types of the signal handler (though I don't understand why this

is needed at all).

Anyway, if I use this function to connect my own signal handler (as
usual with sigc::mem_fun), the compiler complains about mismatching
return types (the errors message is pretty long-winded, STL style, you

don't want to see it I guess...).
Instead of posting the error message from g++, here's the code which
caused it:

// m_view is a TreeView

m_view.signal_button_press_event().connect_notify( sigc::mem_fun(
*this,
&FileBrowser::on_rmb_clicked ) );

// ...

void FileBrowser::on_rmb_clicked()
{
    // ...
}

I don't get what's wrong here.

The function signature of your callback function does not match the function signature of the signal. It should look as follows:

void on_rmb_clicked(GdkEventButton* event)

for connect_notify() or

bool on_rmb_clicked(GdkEventButton* event)

for connect().

Like you already found out, the connect_notify() variant adds the boolean return value for you in such a way that the internal handling of an event is suppressed (which means a value of false, I think).

Regards,

 Martin



--
Matthias Kaeppler

_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
http://mail.gnome.org/mailman/listinfo/gtkmm-list






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