2
votes

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.

1
You are quickly escaping where I can help, but on the first question: Are you not within a class at all? I mean, unless this is being done in your main() function, you should be in a class of some kind, right? Also, there is a way to pass signals directly to a function that is outside a class structure: developer.gnome.org/gtkmm-tutorial/unstable/…Christian Smith

1 Answers

2
votes

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:

Gtk::CellRendererCombo *combo = manage (new Gtk::CellRendererCombo);
combo->signal_changed ().connect (sigc::mem_fun (*this, &ExampleWindow::on_combo_changed);
Gtk::TreeViewColumn *column = manage (new Gtk::TreeViewColumn ("Title", *combo));
column->add_attribute (*combo, "model", model_column_record.combo_model);
column->add_attribute (*combo, "text-column", model_column_record.combo_text_column);
treeview.append_column (*column);