I am trying to make a wrapper for a Gtk click signal to hook into my event system. The Gtk way to handle click events would be like this:
auto button = new Gtk::Button();
button->signal_clicked().connect(...);
So, to add it to my system I created a function called fromSignal which takes two inputs and I will bind them together. The problem that I am running into is on the callback(); line.
error: no match for call to '(std::_Bind<Glib::SignalProxy<void()> (Gtk::Button::*(Gtk::Widget*))()>) ()'
[build] 18 | callback();
[build] | ~~~~~~~~^~
Here is the wrapper:
template <typename T>
void _signalCallback(_Bind<Glib::SignalProxy<void()> (T::*(Widget*))()> callback) {
callback();
printf("callback\n");
}
template <typename T>
void fromSignal(Gtk::Widget* widget, Glib::SignalProxy<void()> (T::*f)()) {
auto b = std::bind(f, widget);
_signalCallback<T>(b);
}
void main() {
auto button = new Gtk::Button();
fromSignal<Gtk::Button>(button, &Gtk::Button::signal_clicked);
}
I tried changing the definition of _signalCallabck which then gives me the following error:
void _signalCallback(function<Glib::SignalProxy<void()>()> callback);
// The error message:
error: could not convert 'b' from 'std::_Bind<Glib::SignalProxy<void()> (Gtk::Button::*(Gtk::Widget*))()>' to 'std::function<Glib::SignalProxy<void()>()>'
[build] 26 | _signalCallback<T>(b);
[build] | ^
[build] | |
[build] | std::_Bind<Glib::SignalProxy<void()> (Gtk::Button::*(Gtk::Widget*))()>
What is the correct way to do this? Am I overly complicating this?
_Bind, is a symbol reserved by the compiler and standard library. If you need to use such symbols then I would argue that it's a sign that you're doing something wrong.functiontype as a parameter like my last block of code, but I couldn't get that working.template<typename F> void _signalCallback(F callback) { /* ... */ }. Similar change tofromSignal. Couple that with lambdas.bind(f, widget)(is thatstd:bind?) cannot be invoked with no arguments. Could you provide an explanation of why it should work that way? Maybe write out what the expression would be without thebind?