标题中引用的注释通常可以在 的文档中找到GTk4
。我的问题是:是否有一种技术方法可以检查程序以确定是否已及时发布所有相关数据。我想通过一个基于问题的示例来说明这一点在 GTK4 中使用字符串填充下拉列表。
我对程序进行了如下测试:
#include"dropdown-glist.h"
// callback function
void cb_test(GtkDropDown *self,GParamSpec *spec, gpointer data)
{
GObject* object = gtk_drop_down_get_selected_item (self);
const char *key = gtk_string_object_get_string(GTK_STRING_OBJECT(object));
gchar *value =g_hash_table_lookup (data, key);
g_print("select: %s %s\n",key,value);
}
void activate (GtkApplication *app, gpointer data)
{
GtkWidget *window;
window =gtk_application_window_new(app);
gtk_widget_set_size_request(window,50,50);
//GHashTable persists after "activate"
GHashTable *hash_table = g_hash_table_new(g_str_hash,g_str_equal);
GtkWidget *drop_down = gtk_drop_down_new(NULL,NULL);
g_hash_table_insert(hash_table,"Key0","value0");
g_hash_table_insert(hash_table,"Key1","value1");
g_hash_table_insert(hash_table,"Key2","value2");
g_hash_table_insert(hash_table,"Key3","value3");
guint hash_size;
/* Get the keys, which are strings, as an array */
gpointer key_array = g_hash_table_get_keys_as_array (hash_table, &hash_size);
/* Create a new GtkStringList model from the array of strings. */
GtkStringList *stringlist = gtk_string_list_new (key_array);
/* Set the model as the source for the dropdown menu. */
gtk_drop_down_set_model (GTK_DROP_DOWN(drop_down), G_LIST_MODEL(stringlist));
// nothing selected
gtk_drop_down_set_selected (GTK_DROP_DOWN (drop_down),GTK_INVALID_LIST_POSITION);
//only here so that changes in the dropdown do not lead to a callback beforehand
g_signal_connect(drop_down, "notify::selected-item", G_CALLBACK(cb_test),hash_table);
GtkWidget *box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,10);
gtk_box_append(GTK_BOX(box),drop_down);
gtk_window_set_child(GTK_WINDOW(window),box);
gtk_widget_set_visible(window,TRUE);
}
hash_table
在此示例中,是否有一种技术方法可以检查我是否必须被释放?
谢谢您的解释性答复。