Frage

I made a treeview with a treestore as model. The window is shown as expected, but when I click in the "+" to expand the items, I get this message:

GLib-CRITICAL **: Source ID 221 was not found when attempting to remove it

Here is my code:

#include <gtk/gtk.h>

/* compile with: */
/* gcc main.c -o boxy `pkg-config --cflags --libs gtk+-2.0` */

typedef struct {
GtkWidget *toplevel;
GtkWidget *treeview;
} Widgets;

enum { ITEM_PARENT, ITEM_CHILD };

typedef struct {
gint tipo;
gint id;
gchar *nombre;
gint cantidad;
} Lista;

void addColumn (GtkTreeView *tv, const gchar* title, gint pos) {
GtkCellRenderer *tmp;
tmp = gtk_cell_renderer_text_new ();
g_object_set (tmp, "editable", TRUE, "editable-set", TRUE, NULL);
gtk_tree_view_insert_column_with_attributes (tv, -1, title, tmp, "text", pos, NULL);
}

void setupTree (GtkTreeView *tv) {
const Lista lista[] = {
    {ITEM_PARENT, 125, "Superman", 2},
    {ITEM_CHILD, 23, "Batman", 1},
    {ITEM_CHILD, 7, "Hulk", 5},
    {ITEM_PARENT, 65, "Iron Man", 2},
    {-1, -1, NULL, -1}
};
GtkTreeStore *model;
GtkTreeIter last;
gint pos;
model = gtk_tree_store_new (3, G_TYPE_INT, G_TYPE_STRING, G_TYPE_INT);
addColumn (tv, "ID", 0);
addColumn (tv, "Nombre", 1);
addColumn (tv, "Cantidad", 2);
for (pos = 0; lista[pos].tipo != -1; pos++) {
    GtkTreeIter iter;
    if (lista[pos].tipo == ITEM_PARENT) {
        gtk_tree_store_append (model, &iter, NULL);
        last = iter;
    } else if (lista[pos].tipo == ITEM_CHILD) {
        gtk_tree_store_append (model, &iter, &last);
    }
    gtk_tree_store_set (model, &iter, 0, lista[pos].id, 1, lista[pos].nombre, 2, lista[pos].cantidad, -1);
}
gtk_tree_view_set_model (tv, GTK_TREE_MODEL (model));
g_object_unref (model);
}

int main (int argc, char *argv[]) {
Widgets *ptr;
GtkWidget *scroll;
gtk_init (&argc, &argv);
ptr = g_slice_new0(Widgets);
ptr->toplevel = gtk_window_new (GTK_WINDOW_TOPLEVEL);
scroll = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scroll), GTK_SHADOW_OUT);
ptr->treeview = gtk_tree_view_new ();
setupTree (GTK_TREE_VIEW (ptr->treeview));

g_signal_connect (ptr->toplevel, "destroy", G_CALLBACK (gtk_main_quit), NULL);

gtk_container_set_border_width (GTK_CONTAINER (ptr->toplevel), 10);
gtk_container_add (GTK_CONTAINER (scroll), ptr->treeview);
gtk_container_add (GTK_CONTAINER (ptr->toplevel), scroll);
gtk_widget_show_all (ptr->toplevel);
gtk_main ();
g_slice_free (Widgets, ptr);
return 0;
}

Any ideas?

War es hilfreich?

Lösung

This isn't a bug in your code, and it's not a crash either. It's actually just a warning that g_source_remove() was called to disconnect a certain event handler that was already disconnected, in this case, in code that is part of gtk.

The warning itself was introduced in glib 2.39, in this commit, and seems like only arch linux users are affected by it because other distros haven't updated yet.

In most cases this is completely harmless, and only an annoyance. Might be worth a look if it originates with a g_source_remove() call in your own code.

Set a breakpoint on g_log to find what's causing it:

(gdb) break g_log
Breakpoint 1 at 0x7ffff5ea5a70
(gdb) c
Continuing.

Breakpoint 1, 0x00007ffff5ea5a70 in g_log () from /usr/lib/libglib-2.0.so.0
(gdb) bt
#0  0x00007ffff5ea5a70 in g_log () from /usr/lib/libglib-2.0.so.0
#1  0x00007ffff5e9d9dc in g_source_remove () from /usr/lib/libglib-2.0.so.0
#2  0x00007ffff79bd0f5 in ?? () from /usr/lib/libgtk-x11-2.0.so.0
#3  0x00007ffff79cc1a4 in ?? () from /usr/lib/libgtk-x11-2.0.so.0
#4  0x00007ffff79cda66 in ?? () from /usr/lib/libgtk-x11-2.0.so.0
#5  0x00007ffff78d7435 in ?? () from /usr/lib/libgtk-x11-2.0.so.0
#6  0x00007ffff616e3d8 in g_closure_invoke () from /usr/lib/libgobject-2.0.so.0
#7  0x00007ffff617fb1b in ?? () from /usr/lib/libgobject-2.0.so.0
#8  0x00007ffff6187719 in g_signal_emit_valist () from /usr/lib/libgobject-2.0.so.0
#9  0x00007ffff6187d02 in g_signal_emit () from /usr/lib/libgobject-2.0.so.0
#10 0x00007ffff79e6fe4 in ?? () from /usr/lib/libgtk-x11-2.0.so.0
#11 0x00007ffff78d5be4 in gtk_propagate_event () from /usr/lib/libgtk-x11-2.0.so.0
#12 0x00007ffff78d5f9b in gtk_main_do_event () from /usr/lib/libgtk-x11-2.0.so.0
#13 0x00007ffff75519cc in ?? () from /usr/lib/libgdk-x11-2.0.so.0
#14 0x00007ffff5e9eb84 in g_main_context_dispatch () from /usr/lib/libglib-2.0.so.0
#15 0x00007ffff5e9edc8 in ?? () from /usr/lib/libglib-2.0.so.0
#16 0x00007ffff5e9f08a in g_main_loop_run () from /usr/lib/libglib-2.0.so.0
#17 0x00007ffff78d5087 in gtk_main () from /usr/lib/libgtk-x11-2.0.so.0
#18 0x000000000040152f in main ()

The backtrace goes all the way from gtk_main to g_log without passing a single time through your code, so this probably affects any gtk program with a treeview.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top