Unable to pass additional argument to signal handling function

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Unable to pass additional argument to signal handling function

Gtkmm mailing list
I'm trying to call a function that accepts one parameter when user
clicks a menu item. I tried this:

menu_item.signal_activate().connect(sigc::bind<Gtk::Window>(sigc::ptr_fun(&handler_fun),
*this))

The method I put this code into is of class that inherits from
Gtk::Window. The handler_fun function does not belong to any class. I
saw this in official tutorial
(https://developer.gnome.org/gtkmm-tutorial/stable/sec-binding-extra-arguments.html.en)
but it doesn't work for me (the code won't compile). The error I'm
getting is that there is no such function.
_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: Unable to pass additional argument to signal handling function

Gtkmm mailing list
> The error I'm getting is that there is no such function.

About which function? Anyway, please show all the code. As written, you haven't proven that the function *does* exist! And the code you posted doesn't match any in the link you showed.

_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: Unable to pass additional argument to signal handling function

Gtkmm mailing list
I also suspect you'll need to pass that as std::ref(*this), otherwise I think sigc++ will assume you want a copy, which is unlikely to end well.


_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: Unable to pass additional argument to signal handling function

Gtkmm mailing list
In reply to this post by Gtkmm mailing list
If you want to pass a widget to a signal handler, I suggest you pass a widget pointer. See e.g.
https://gitlab.gnome.org/GNOME/gtkmm-documentation/blob/gtkmm-3-24/examples/book/buildapp/step5/exampleapplication.cc line 46.

In your case:
menu_item.signal_activate().connect(sigc::bind<Gtk::Window*>(sigc::ptr_fun(&handler_fun), this));
Of course you must change handler_fun() accordingly.

I also repeat Daniel's question: Which function does not exist? If it's one of the sigc:: functions, you probably have to add an #include.
On 2019-02-18 14:39, Радомир Хаџић via gtkmm-list wrote:
I'm trying to call a function that accepts one parameter when user
clicks a menu item. I tried this:

menu_item.signal_activate().connect(sigc::bind<Gtk::Window>(sigc::ptr_fun(&handler_fun),
*this))

The method I put this code into is of class that inherits from
Gtk::Window. The handler_fun function does not belong to any class. I
saw this in official tutorial
(https://developer.gnome.org/gtkmm-tutorial/stable/sec-binding-extra-arguments.html.en)
but it doesn't work for me (the code won't compile). The error I'm
getting is that there is no such function.

_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: Unable to pass additional argument to signal handling function

Gtkmm mailing list
On Tue, 19 Feb 2019 at 08:42, Kjell Ahlstedt via gtkmm-list <[hidden email]> wrote:
If you want to pass a widget to a signal handler, I suggest you pass a widget pointer.
 
 I'm curious why? Other than, I guess, that being more familiar than std::reference_wrapper, but I find the latter increasingly useful to express semantics and avoid the perils of pointers.

_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: Unable to pass additional argument to signal handling function

Gtkmm mailing list
In reply to this post by Gtkmm mailing list
On Thu, 21 Feb 2019 at 19:24, Радомир Хаџић <[hidden email]> wrote:
2019-02-18 15:15 GMT+01:00, Daniel Boles via gtkmm-list <[hidden email]>:
>> The error I'm getting is that there is no such function.
>
> About which function? Anyway, please show all the code. As written, you
> haven't proven that the function *does* exist! And the code you posted
> doesn't match any in the link you showed.

bind. But I don't think that's important now since I've lost the code
anyway. Maybe I was supposed to include some file?

Obviously. <sigc++/bind.h> or IIRC adaptors.h collects this and other stuff together if you want.



_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list