我正在处理一个带有GUI的应用程序,当我尝试在连接处发出信号(sig_showList,来自View)时遇到另一个信号(来自Gtk :: ComboBox的signal_changed)时遇到了麻烦,我非常感谢你的帮助。代码看起来像这样:
" view.h"
class View{
private:
Gtk::ComboBox* combo;
sigc::signal<void,int> sig_showList;
public:
View();
...
};
&#34; view.c&#34;
#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));
...
}
我用g++ -std=c++98 *.cpp -o out $(pkg-config gtkmm-3.0 --cflags --libs)
编译它。我得到的错误是:
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
[实际课程称为&#34; Vista&#34;]
好吧,我不知道这意味着什么!此外,这已经发生了,不知怎的,我设法解决了它,但经过一些重新格式化和重新设计,它再次出现,我不知道该怎么做。它肯定与combo-&gt; signal_clicked()。connect(...)行有关,因为当我删除它时编译很好。
答案 0 :(得分:1)
我发现了什么错误:我尝试发出的信号是sigc :: signal类型,因此在发出时应该将一个int作为参数,但我没有传递任何参数< / p>
答案 1 :(得分:0)
请尝试使用以下命名空间:
namespace sigc { SIGC_FUNCTORS_HAVE_RESULT_TYPE }