[Glade-users] gtk_combo_box_append_text() problem
- From: captain.deadly at gmail.com (Arigead)
- Subject: [Glade-users] gtk_combo_box_append_text() problem
- Date: Wed, 22 Oct 2008 10:47:34 +0100
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Thanks a million for that Carlos I'll go through your code and learn
something about programming gtk, if not some Portuguese ;-)
Carlos Pereira wrote:
Hello,
Here is my code to populate a drop down with text.
I use it in a C++ program, so I pass a vector of strings to populate
the dropdown. It should be easy to change it to use char *.
The comments are in portuguese, sorry.... :-)
Best regards
Carlos
// esta funcao preenche qualquer dropdown simples, 1 coluna de string
void preenche_drop(GtkWidget *DROP, vector<string> CONTEUDO)
{
// preenche um drop down com as strings dentro do vetor CONTEUDO informado
// zera o conteudo atual do drop down
gtk_cell_layout_clear(GTK_CELL_LAYOUT(DROP));
int cont;
GtkListStore *list_store;
GtkCellRenderer *renderer;
GtkTreeIter iter;
list_store = gtk_list_store_new (1, G_TYPE_STRING);
for(cont=0; cont < CONTEUDO.size(); cont++)
{
char conteudo[130];
sprintf(conteudo, "%s", CONTEUDO.at(cont).c_str());
// Add a new row to the model
gtk_list_store_append (list_store, &iter); // add linha vazia
e faz iter apontar para ela
// armazena um valor na lista, na linha apontada por iter, nas
colunas indicadas
// 0 - primeira coluna, e o conteudo da coluna. A lista termina com -1
gtk_list_store_set (list_store, &iter, 0, conteudo, -1);
}
gtk_combo_box_set_model(GTK_COMBO_BOX(DROP), GTK_TREE_MODEL(list_store));
renderer = gtk_cell_renderer_text_new();
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(DROP), renderer, TRUE);
gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(DROP), renderer,
"text", 0, NULL);
// vou deixar aqui pra servir de referencia, mas nao eh verdade para todo
// dropdown criado, pode-se querer ele vazio para que sua alteracao
// chame uma callback function
//mostra o primeiro item no drop down
//gtk_combo_box_set_active(GTK_COMBO_BOX(drop_bds), 0);
}
On Tue, Oct 21, 2008 at 4:48 AM, Arigead <captain.deadly at gmail.com> wrote:
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);
/* Simply add to the combobox */
gtk_combo_box_append_text((GtkComboBox *)vehicleList, "Hello");
Neither of those two methods raise an error on compile time but nothing
is in the drop down list at all?
_______________________________________________
Glade-users maillist - Glade-users at lists.ximian.com
http://lists.ximian.com/mailman/listinfo/glade-users
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFI/va1XlbjSJ5n4BARApARAJ9ekZ6kithU+u2nOX7jyl0bB31MXACg1bIa
QW98qrZz58hchDLOl+TKQAY=
=DmYR
-----END PGP SIGNATURE-----
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]