gtkmm compiler error when connecting signal

755 views Asked by At

I'm working on an application with a GUI and I'm having trouble when trying to emit a signal (sig_showList, from View) at the connect for another signal (signal_changed, from Gtk::ComboBox), I'd really appreciate your help. The code looks something like this:

"view.h"

class View{
 private:
  Gtk::ComboBox* combo;
  sigc::signal<void,int> sig_showList;
 public:
  View();
  ...
};

"view.c"

#include "view.h"
View::View(Glib::RefPtr<Gtk::Builder>& builder){
 builder -> get_widget("combo",combo);
 combo->signal_changed().connect(sigc::mem_fun(&sig_showList,&sigc::signal<void,int>::emit));
 ...
}

I compile it with g++ -std=c++98 *.cpp -o out $(pkg-config gtkmm-3.0 --cflags --libs). The error I'm getting is:

    In file included from /usr/include/sigc++-2.0/sigc++/functors/slot.h:7:0,
                 from /usr/include/sigc++-2.0/sigc++/signal_base.h:29,
                 from /usr/include/sigc++-2.0/sigc++/signal.h:8,
                 from /usr/include/sigc++-2.0/sigc++/sigc++.h:80,
                 from /usr/include/glibmm-2.4/glibmm/thread.h:58,
                 from /usr/include/glibmm-2.4/glibmm.h:87,
                 from /usr/include/gtkmm-3.0/gtkmm.h:87,
                 from vista.cpp:2:
/usr/include/sigc++-2.0/sigc++/adaptors/adaptor_trait.h: In instantiation of ‘sigc::adaptor_functor<T_functor>::result_type sigc::adaptor_functor<T_functor>::operator()() const [with T_functor = sigc::bound_const_mem_functor1<void, sigc::signal<void, int>, const int&>; sigc::adaptor_functor<T_functor>::result_type = void]’:
/usr/include/sigc++-2.0/sigc++/functors/slot.h:103:36:   required from ‘static T_return sigc::internal::slot_call0<T_functor, T_return>::call_it(sigc::internal::slot_rep*) [with T_functor = sigc::bound_const_mem_functor1<void, sigc::signal<void, int>, const int&>; T_return = void]’
/usr/include/sigc++-2.0/sigc++/functors/slot.h:110:37:   required from ‘static void* (* sigc::internal::slot_call0<T_functor, T_return>::address())(void*) [with T_functor = sigc::bound_const_mem_functor1<void, sigc::signal<void, int>, const int&>; T_return = void; sigc::internal::hook = void* (*)(void*)]’
/usr/include/sigc++-2.0/sigc++/functors/slot.h:454:83:   required from ‘sigc::slot0<T_return>::slot0(const T_functor&) [with T_functor = sigc::bound_const_mem_functor1<void, sigc::signal<void, int>, const int&>; T_return = void]’
/usr/include/sigc++-2.0/sigc++/functors/slot.h:1130:26:   required from ‘sigc::slot<T_return, sigc::nil, sigc::nil, sigc::nil, sigc::nil, sigc::nil, sigc::nil, sigc::nil>::slot(const T_functor&) [with T_functor = sigc::bound_const_mem_functor1<void, sigc::signal<void, int>, const int&>; T_return = void]’
vista.cpp:80:105:   required from here
/usr/include/sigc++-2.0/sigc++/adaptors/adaptor_trait.h:251:21: error: no match for call to ‘(sigc::bound_const_mem_functor1<void, sigc::signal<void, int>, const int&>) ()’
   { return functor_(); }
                     ^
In file included from /usr/include/sigc++-2.0/sigc++/adaptors/adaptor_trait.h:9:0,
                 from /usr/include/sigc++-2.0/sigc++/functors/slot.h:7,
                 from /usr/include/sigc++-2.0/sigc++/signal_base.h:29,
                 from /usr/include/sigc++-2.0/sigc++/signal.h:8,
                 from /usr/include/sigc++-2.0/sigc++/sigc++.h:80,
                 from /usr/include/glibmm-2.4/glibmm/thread.h:58,
                 from /usr/include/glibmm-2.4/glibmm.h:87,
                 from /usr/include/gtkmm-3.0/gtkmm.h:87,
                 from vista.cpp:2:
/usr/include/sigc++-2.0/sigc++/functors/mem_fun.h:2373:7: note: candidate is:
 class bound_const_mem_functor1
       ^
/usr/include/sigc++-2.0/sigc++/functors/mem_fun.h:2402:12: note: T_return sigc::bound_const_mem_functor1<T_return, T_obj, T_arg1>::operator()(typename sigc::type_trait<T_arg3>::take) const [with T_return = void; T_obj = sigc::signal<void, int>; T_arg1 = const int&; typename sigc::type_trait<T_arg3>::take = const int&]
   T_return operator()(typename type_trait<T_arg1>::take _A_a1) const
            ^
/usr/include/sigc++-2.0/sigc++/functors/mem_fun.h:2402:12: note:   candidate expects 1 argument, 0 provided
In file included from /usr/include/sigc++-2.0/sigc++/functors/slot.h:7:0,
                 from /usr/include/sigc++-2.0/sigc++/signal_base.h:29,
                 from /usr/include/sigc++-2.0/sigc++/signal.h:8,
                 from /usr/include/sigc++-2.0/sigc++/sigc++.h:80,
                 from /usr/include/glibmm-2.4/glibmm/thread.h:58,
                 from /usr/include/glibmm-2.4/glibmm.h:87,
                 from /usr/include/gtkmm-3.0/gtkmm.h:87,
                 from vista.cpp:2:
/usr/include/sigc++-2.0/sigc++/adaptors/adaptor_trait.h:251:21: error: return-statement with a value, in function returning 'void' [-fpermissive]
   { return functor_(); }
                     ^
make: *** [all] Error 1

[The actual class is called "Vista"]

So well, I have no idea what that means! Moreover this had already happened and somehow I managed to solve it but after some reformat and redesign it showed up again and I don't know what to do. It definitely has to do with the combo->signal_clicked().connect(...) line, because when I remove it compiles fine.

2

There are 2 answers

0
Dipak D Desai On

Please try to used below namespace:

namespace sigc { SIGC_FUNCTORS_HAVE_RESULT_TYPE }
0
Chrischpo On

I found out what was wrong: the signal I'm trying to emit is of type sigc::signal so it should take one int as an argument when emitted, but I wasn't passing any arguments