GNOME Bugzilla – Bug 94170
TreeModelColumns cannot be of type "UNSIGNED SHORT"
Last modified: 2009-08-15 18:40:50 UTC
Try to create a TreeModel::ColumnRecord with a column like this: Gtk::TreeModelColumn<unsigned short> my_unsigned_short; and you get a lot of: "GLib-GObject-WARNING **: unable to set property `text' of type `gchararray' from value of type `glibmm__CustomBoxed_Us'" and cannot assign values to this column. I didn't try this with other variable types and use normal signed integers now. Thank you for your time, Leslie
I think we need to see some simple-as-possible compilable test code to show this.
There you go.. The example clearly shows that both unsigned and signed int work, but none of the short types. #include <gtkmm/box.h> #include <gtkmm/window.h> #include <gtkmm/main.h> #include <gtkmm/liststore.h> #include <gtkmm/treeview.h> /* column definition */ class MyColumns : public Gtk::TreeModel::ColumnRecord { public: inline MyColumns() { add(s_sh_test); add(us_sh_test); add(s_int_test); add(us_int_test); } Gtk::TreeModelColumn<signed short> s_sh_test; Gtk::TreeModelColumn<unsigned short> us_sh_test; Gtk::TreeModelColumn<signed int> s_int_test; Gtk::TreeModelColumn<unsigned int> us_int_test; }; /* main window */ class MainWindow : public Gtk::Window { public: MainWindow(); inline ~MainWindow() {} protected: Gtk::VBox box1; Gtk::TreeView myview; MyColumns mycolumns; }; MainWindow::MainWindow() { Glib::RefPtr<Gtk::ListStore> mylist_ListStore = Gtk::ListStore::create(mycolumns); Gtk::TreeModel::iterator mylistRowPtr; Gtk::TreeModel::Row mylistRow; myview.set_model(mylist_ListStore); myview.append_column("Signed Short", mycolumns.s_sh_test); myview.append_column("Unsigned Short", mycolumns.us_sh_test); myview.append_column("Signed Int", mycolumns.s_int_test); myview.append_column("Unsigned Int", mycolumns.us_int_test); for (int i = 0; i <= 3; i++) { (myview.get_column(i))->set_clickable(TRUE); (myview.get_column(i))->set_resizable(TRUE); (myview.get_column(i))->set_sort_indicator(TRUE); } this->add(box1); mylistRowPtr = mylist_ListStore->append(); mylistRow = *mylistRowPtr; mylistRow[mycolumns.s_sh_test] = 1; mylistRow[mycolumns.us_sh_test] = 1; mylistRow[mycolumns.s_int_test] = 1; mylistRow[mycolumns.us_int_test] = 1; box1.pack_start(myview); myview.show(); box1.show(); } /* entry point */ int main(int argc, char **argv) { Gtk::Main *test = new Gtk::Main(argc, argv); MainWindow mw; test->run(mw); return(0); }
Note: If you change the myview.append_column("Signed Short", mycolumns.s_sh_test); myview.append_column("Unsigned Short", mycolumns.us_sh_test); to myview.append_column_editable(...); the code won't even compile.
This is a GLib problem -- there is no GValue implementation for "unsigned short". However, with gtkmm2 a custom GValue implementation is generated automatically and should work. You're getting this error message "GLib-GObject-WARNING **: unable to set property `text' of type `gchararray' from value of type `glibmm__CustomBoxed_Us'" because you'd have to set up your own cell_data_func callbacks -- GTK+ doesn't know about the type. However, the reason why there's no GValue implementation for signed or unsigned short is that it wouldn't save you any space (GValue is padded up anyway) and rarely needed at all. --Daniel
Thank you, Daniel - but why is +You're getting this error message + [...] +because you'd have to set up your own cell_data_func callbacks -- +GTK+ doesn't know about the type. not true for the bool-type, for which a call_data_func_cb is also necessary?
Daniel?
The cell data callback is probably necessary for you because you're using Gtk::CellRendererString to display it -- if you'd use Gtk::CellRendererToggle it'd work out of the box. GTK+ does know about the bool type, it's just that there isn't a standard CellRenderer that does what you want to do with it (displaying "true" or "false" I guess). You can see what types are available by looking at the Glib reference docs for Glib::Value<> specializations. (BTW: Murray, why did you exclude the Glib::Value<> specializations for strings from the docs? I don't see the reason for doing so especially since all the other ones are still shown.)