Gtk4: How to set combo box model data?

Here is a snippet

#include <gtk/gtk.h>

enum {

static void startapp(GtkApplication *app)
    GtkTreeIter iter;
    GtkWindow *window = (GtkWindow*)gtk_window_new();
    GtkListStore *store = gtk_list_store_new(NUM_COLS, G_TYPE_STRING);
    GtkWidget *combo = gtk_combo_box_new_with_model_and_entry((GtkTreeModel*)store);
    gtk_window_set_application(window, app);
    gtk_list_store_append(store, &iter);
    gtk_list_store_set(store, &iter, FIRST_COLUMN, "Foo", -1);
    gtk_window_set_child(window, combo);

int main (int response, char **name)
  GtkApplication *app = gtk_application_new ("", G_APPLICATION_FLAGS_NONE);
  g_signal_connect(app, "activate", (GCallback)startapp, NULL);
  response = g_application_run((GApplication*)app, response, name);
  return response;

I can create rows but cant seem to put data in them. My combo box drops down with an empty list.

@bretantonio have you checked out the new GtkDropdown widget? It might be easier to use.

I think you are missing a call to gtk_combo_box_set_entry_text_column(), maybe ?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.