[Glade-users] gtk_combo_box_append_text() problem



On Tue, 2008-10-21 at 08:48 +0100, Arigead wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

jonathan at blueplanet.cl wrote:
Hi,

Basically in my C code I get the comboBox with gtk_builder_get_object()
and then call gtk_combo_box_append_text() this gives me an error:

(gmpg:12154): Gtk-CRITICAL **: gtk_combo_box_append_text: assertion
`GTK_IS_LIST_STORE (combo_box->priv->model)' failed

Did you created the GtkListStore model for that combo box? That warning
was produced because you didn't set the proper model.

Check the info of gtk_combo_box_set_model ().


Thanks All for getting back to me,

I'm a bit confused by the GtkListStore model now. If I want to just
store a list of strings I create a GtkListStore:

    GtkListStore            *list_store;
    list_store = gtk_list_store_new (1, G_TYPE_STRING);

Now set this to be the model of my combobox:

    gtk_combo_box_set_model((GtkComboBox *) MyComboBox,
                            (GtkTreeModel *)list_store);

That has gotten rid of the error message OK but I can't add to the list
of items in the combobox. I've tried adding to the ListStore and the
Combobox but nothing shows up when I display the interface.

    GtkTreeIter iter;

    /* Add a new row to the model */
    gtk_list_store_append (list_store, &iter);
    gtk_list_store_set (list_store, &iter, 0, "Hello", -1);

You have to specify what column in the list to display, just like in the
treeviews. One more step should be enough:

GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (MyComboBox), renderer,
TRUE);
gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (MyComboBox), renderer,
"text", 0);





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]