Gtkmm:将信号处理程序连接到 TreeView 中的组合框
这是对此的后续问题: 如何将 ComboBox 添加到 TreeView 列?< /a>
我能够将 ComboBox 放置在 TreeView 中,并包含我需要的选项。但我似乎无法弄清楚如何将信号处理程序连接到它。所有现有文档都显示这样的连接语句:
m_Combo.signal_changed().connect(sigc::mem_fun(*this, &ExampleWindow::on_combo_changed) );
但我不在 Window 类定义内,因此没有 *this 对象。我正在使用 Glade 创建 GUI 的基本结构。
此外,所有现有文档都显示信号处理程序执行类似以下操作:
void ExampleWindow::on_combo_changed()
{
Glib::ustring text = m_Combo.get_active_text();
if(!(text.empty()))
std::cout << "Combo changed: " << text << std::endl;
}
其中“m_Combo”对象是全局的,并且可以简单地访问。但是当 ComboBox 位于 TreeView 内部时,它是动态的。我将如何实际访问组合框?通过参数传递一些东西? signal_changed().connect() 函数似乎对其参数非常挑剔。不管我给它什么,它都会在编译器错误中吐出(字面上的)100 行乱码。结束于:
/usr/include/sigc++-2.0/sigc++/functors/mem_fun.h:6196:1: note: template<class T_arg1, class T_arg2, class T_arg3, class T_arg4, class T_arg5, class T_arg6, class T_arg7, class T_return, class T_obj, class T_obj2> sigc::bound_const_volatile_mem_functor7<T_return, T_obj, T_arg1, T_arg2, T_arg3, T_arg4, T_arg5, T_arg6, T_arg7> sigc::mem_fun(T_obj&, T_return (T_obj2::*)(T_arg1, T_arg2, T_arg3, T_arg4, T_arg5, T_arg6, T_arg7)const volatile)
make: *** [src/RTT_Client_GTK.o] Error 1`
没有让我的调试生活变得更容易。
This is a follow-up question to this:
How do I add a ComboBox to a TreeView column?
I was able to place a ComboBox inside a TreeView with the options I need. But I can't seem to figure out how to connect a signal handler to it. All the existing documentation shows connect statements like this:
m_Combo.signal_changed().connect(sigc::mem_fun(*this, &ExampleWindow::on_combo_changed) );
But I'm not inside a Window class definition, and thus have no *this object. I'm using Glade to create the basic structures of the GUI.
Also, all the existing documentation shows the signal handler doing something like this:
void ExampleWindow::on_combo_changed()
{
Glib::ustring text = m_Combo.get_active_text();
if(!(text.empty()))
std::cout << "Combo changed: " << text << std::endl;
}
Where the "m_Combo" object is global, and can just be simply accessed. But When the ComboBox is inside a TreeView, it's dynamic. How would I go about actually accessing the ComboBox? Pass something through via a parameter? The signal_changed().connect() function seems to be really picky about its parameters. No matter what I give it, it spits out (literally) 100 lines of gibberish in compiler errors. Ends with:
/usr/include/sigc++-2.0/sigc++/functors/mem_fun.h:6196:1: note: template<class T_arg1, class T_arg2, class T_arg3, class T_arg4, class T_arg5, class T_arg6, class T_arg7, class T_return, class T_obj, class T_obj2> sigc::bound_const_volatile_mem_functor7<T_return, T_obj, T_arg1, T_arg2, T_arg3, T_arg4, T_arg5, T_arg6, T_arg7> sigc::mem_fun(T_obj&, T_return (T_obj2::*)(T_arg1, T_arg2, T_arg3, T_arg4, T_arg5, T_arg6, T_arg7)const volatile)
make: *** [src/RTT_Client_GTK.o] Error 1`
Not making my life trying to debug any easier.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,如果您使用 Glade 创建 UI,则可能意味着您正在使用 Gtk::Builder 来加载它(因为 Glade 不再支持其旧的 .glade 格式)。 Gtk::Builder 有一个 get_widget_衍生() 函数允许您将 GtkBuilder .xml 文件中的小部件直接提取到派生的小部件类中。
其次,您不会直接使用 ComboBox,而是使用 CellRendererCombo 如果您正在使用 TreeView。你会做类似的事情:
Firstly, if you're using Glade to create your UI, it probably means that you're using Gtk::Builder to load it (since Glade no longer supports its old .glade format). Gtk::Builder has a get_widget_derived() function that allows you to extract a widget from the GtkBuilder .xml file directly into your derived widget class.
Secondly, you wouldn't be using a ComboBox directly, but a CellRendererCombo if you're using a TreeView. You would do something like: