GtkEntryCompletion is not reusable and Crash directly
Steps to reproduce
#include <gtk/gtk.h>
static void activate(GtkApplication *app, gpointer user_data) {
// Create a new window
GtkWidget *window = gtk_application_window_new(app);
gtk_window_set_title(GTK_WINDOW(window), "GTK4 Entry Completion Example");
gtk_window_set_default_size(GTK_WINDOW(window), 300, 200);
// Create a box layout
GtkWidget *box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
gtk_window_set_child(GTK_WINDOW(window), box);
// Create an entry
GtkWidget *entry = gtk_entry_new();
gtk_entry_set_placeholder_text(GTK_ENTRY(entry), "Type something...");
// Create a completion
GtkEntryCompletion *completion = gtk_entry_completion_new();
gtk_entry_completion_set_text_column(completion, 0);
// Create a list store for completion data
GtkListStore *store = gtk_list_store_new(1, G_TYPE_STRING);
GtkTreeIter iter;
gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter, 0, "Completion Item 1", -1);
gtk_entry_completion_set_model(completion, GTK_TREE_MODEL(store));
g_object_unref(store);
// Connect completion to entry
gtk_entry_set_completion(GTK_ENTRY(entry), completion);
g_object_ref (completion);
gtk_entry_set_completion(GTK_ENTRY(entry), NULL);
gtk_entry_set_completion(GTK_ENTRY(entry), completion);
// Add entry to the window
gtk_box_append(GTK_BOX(box), entry);
gtk_window_present(window);
}
int main(int argc, char **argv) {
// Initialize GTK application
GtkApplication *app = gtk_application_new("com.example.entry_completion", G_APPLICATION_FLAGS_NONE);
g_signal_connect(app, "activate", G_CALLBACK(activate), NULL);
int status = g_application_run(G_APPLICATION(app), argc, argv);
g_object_unref(app);
return status;
}
Current behavior
Demo crash directly.
Expected outcome
Demo should not crash.
Version information
gtk 4.12.5