c++ - 如何从 gtkmm 树视图中获取选定的行
问题描述
我有一个使用 ListStore 的 gtkmm TreeView。我将其用作静态列表选择菜单。我在查看用户何时更改行以及选择了哪一行时遇到问题。
我试图使用m_TreeView.signal_row_activated().connect( sigc::mem_fun(*this, &optionList::row_activated) );
,但得到的错误
error: no match for call to ‘(sigc::bound_mem_functor0<void, optionList>) (const Gtk::TreePath&, Gtk::TreeViewColumn* const&)’ { return functor_(_A_arg1, _A_arg2); }
我也尝试使用更改的信号,但我收到相同的错误。我在谷歌上发现这些错误并没有什么成果。我还没有看到另一种创建静态列表选择菜单的方法。
我的代码如下:
optionList::optionList() {
set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
add(m_TreeView);
m_refListStore = Gtk::ListStore::create(m_Columns);
m_TreeView.set_model(m_refListStore);
m_TreeView.set_activate_on_single_click(true);
std::array<Glib::ustring, 3> options = {"Status", "Plugins", "Config"};
for(const auto & option : options) {
std::ostringstream text;
text << option;
Gtk::TreeModel::Row row = *(m_refListStore->append());
row[m_Columns.m_col_text] = text.str();
}
m_TreeView.append_column("Options", m_Columns.m_col_text);
m_TreeView.signal_state_changed().connect( sigc::mem_fun(*this, &optionList::row_activated) ); //This line produces the error
show_all_children();
}
该optionList::row_activated
功能只是一个cout
,所以我知道它至少被激活了。如果我删除连接线,那么它会编译并运行良好,但我无法判断它是否被选中。
每次选择不同的行时,我都希望A row has been selected
在控制台中看到该短语(因为那是输出)。row_activated
但是,我什至无法编译包含上述行的代码。
至少,我怎样才能解决这个连接问题,以便代码可以编译和激活功能?
编辑:我相信我搞砸了,需要使用sigc::bind()
解决方案
我能想出的最佳答案是我没有正确通过,为此我需要使用
m_TreeView.signal_state_changed().connect( sigc::bind(sigc::mem_fun(*this, &optionList::row_activated), any parameters) );
推荐阅读
- sql-server - Case When Result 中的表达式
- android - 活动中有很多框架布局
- selenium - 使用 selenium java 3.11 库编译代码时出现“错误:无法访问 Killable”
- python - ElementTree XPath - 获取所有标签
- android - 在 Fragment 中创建相机预览
- python - Pandas:使用基于不同 DF 的自定义列创建 DF
- induction - Dafny 归纳引理:不能推断归纳假设的后置条件
- android - 如何检查是否创建了 Intent
- git - Git 提交 2 次
- reactjs - 将参数传递给嵌套的 React Navigation 状态