sigc::mem_fun并从类方法传递params
sigc::mem_fun and pass params from a class method
在gtkmm中,我可以在构造函数中使用类似的东西:
// Gtk::ImageMenuItem *iQuit;
iQuit->signal_activate().connect (sigc::mem_fun (*this, &FormUI::on_quit_activated) );
但我想使用一种方法来设置项目的属性,例如:
void FormUI::SetItemProps (Gtk::ImageMenuItem *i, const Glib::ustring& _l, ?what should I put here?)
{
i->set_use_stock (true);
i->set_label (_l);
i->signal_activate().connect (sigc::mem_fun (*this, ???) ); <-- what to pass there
}
所以我可以在构造函数中使用这样的东西:
SetItemProps (iQuit, "gtk-quit", &FormUI::on_quit_activated);
有什么想法吗?
您可能喜欢使用typedef:
typedef void (FormUI::*function_ptr)();
void FormUI::SetItemProps (Gtk::ImageMenuItem *i, const Glib::ustring& _l, function_ptr fun)
{
i->set_use_stock (true);
i->set_label (_l);
i->signal_activate().connect (sigc::mem_fun (*this, fun) );
}
方法on_quit_activated()必须是已声明的类型。
要呼叫,请使用
SetItemProps (iQuit, "gtk-quit", &FormUI::on_quit_activated);
您可能想要使用sigc::bind():https://developer.gnome.org/gtkmm-tutorial/unstable/sec-binding-extra-arguments.html.en
相关文章:
- 如果C++类在类方法中具有动态分配,但没有构造函数/析构函数或任何非静态成员,那么它仍然是POD类型吗
- 在静态库中嵌入类方法
- 如何制作一个将函数作为参数的类方法
- 从父类方法返回子类对象
- 使用用户定义的参数调用future/async并调用类方法
- 重载类方法的不明确调用
- 单独定义模板化嵌套类方法的正确语法
- 绑定派生类方法C++从实例范围之外的分隔 std::function 变量调用
- 如何访问由共享指针保存的类方法?
- 将子类方法声明为基类的友元
- 我的模板类方法返回错误类型?
- Qt将信号与另一个类方法连接
- 我无法使用C++指针指向类方法返回的 std::vector
- 如何在成为指向基类的指针后保留对子类方法的使用?
- 检查类方法中是否(此 == nullptr)
- 从基类实例调用派生类方法而不进行强制转换
- 函数从唯一代码调用正确的子类方法
- C++ - 如何在不静态的情况下将回调绑定到类方法?
- C++ |DLL / EXE - 如何从导出的类调用另一个类方法?
- sigc::mem_fun并从类方法传递params