C语言 GLib-CRITICAL **:尝试删除时未找到源 ID XXX

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23199699/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 11:02:08  来源:igfitidea点击:

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

cgtkgtk2gtktreeview

提问by Joel

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?

有任何想法吗?

回答by dequis

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.

这不是您代码中的错误,也不是崩溃。它实际上只是一个警告,它g_source_remove()被调用以断开某个已经断开连接的事件处理程序,在这种情况下,在作为 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.

警告本身是在 glib 2.39 中引入的,在这个提交中,似乎只有 arch linux 用户受到它的影响,因为其他发行版尚未更新。

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.

在大多数情况下,这是完全无害的,只是一种烦恼。如果它源自g_source_remove()您自己的代码中的调用,则可能值得一看。

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

在 g_log 上设置断点以查找导致它的原因:

(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.

回溯从 gtk_main 一直到 g_log 没有通过你的代码一次,所以这可能会影响任何带有树视图的 gtk 程序。