gtk_list_store_clear() function raises Segmentation Fault in C

北城以北 提交于 2021-01-29 03:00:20

问题


I am writing a program using GTK in C. I am using GtkListStore to display some data coming from a database. After a particular signal I want to remove all the rows in the GtkListStore. I used gtk_list_store_clear() function, but it raises Segmentation Fault.

What is wrong with my code?

//Globally declared
GtkListStore *liststore2;

//Inside main() function
liststore2 = GTK_LIST_STORE(gtk_builder_get_object(builder, "liststore2"));

//Inside signal handler function
gtk_list_store_clear(liststore2); //Error comes from here

回答1:


If you destroy the builder object (using g_object_unref(builder)) before the signal handler runs, liststore2 may point to freed memory.

That happens if liststore2 is free-standing (i.e., not ref'ed by something else, for example a GtkTreeView)

gtk_builder_get_object does not increment the reference count on object



来源:https://stackoverflow.com/questions/58961074/gtk-list-store-clear-function-raises-segmentation-fault-in-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!