gtk_list_store_clear()函数在C中引发分段错误 [英] gtk_list_store_clear() function raises Segmentation Fault in C
问题描述
我正在C中使用GTK编写程序.我正在使用GtkListStore来显示一些来自数据库的数据.发出特定信号后,我想删除GtkListStore中的所有行.我使用了gtk_list_store_clear()函数,但这会引起分段错误.
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.
我的代码有什么问题?
//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
推荐答案
如果在信号处理程序运行之前破坏构建器对象(使用 g_object_unref(builder)
),liststore2可能指向释放的内存.
If you destroy the builder object (using g_object_unref(builder)
) before the signal handler runs, liststore2 may point to freed memory.
如果liststore2是独立的(即未被其他内容(例如GtkTreeView)引用),则会发生这种情况
That happens if liststore2 is free-standing (i.e., not ref'ed by something else, for example a GtkTreeView)
gtk_builder_get_object 可以不是增加对象的引用计数
gtk_builder_get_object does not increment the reference count on object
这篇关于gtk_list_store_clear()函数在C中引发分段错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!