——————–pro——————————-
INCLUDEPATH += /usr/include/gtk-3.0 \
/usr/include/at-spi2-atk/2.0 \
/usr/include/at-spi-2.0 \
/usr/include/dbus-1.0 \
/usr/lib/x86_64-linux-gnu/dbus-1.0/include \
/usr/include/gtk-3.0 /usr/include/gio-unix-2.0 \
/usr/include/cairo /usr/include/pango-1.0 \
/usr/include/harfbuzz \
/usr/include/pango-1.0 \
/usr/include/fribidi \
/usr/include/harfbuzz \
/usr/include/atk-1.0 \
/usr/include/cairo \
/usr/include/pixman-1 \
/usr/include/uuid \
/usr/include/freetype2 \
/usr/include/gdk-pixbuf-2.0 \
/usr/include/libpng16 \
/usr/include/x86_64-linux-gnu \
/usr/include/libmount \
/usr/include/blkid \
/usr/include/glib-2.0 \
/usr/lib/x86_64-linux-gnu/glib-2.0/include\
/usr/include/
LIBS += -pthread \
-pthread \
-lgtk-3 \
-lgdk-3 \
-lpangocairo-1.0 \
-lpango-1.0 \
-lharfbuzz \
-latk-1.0 \
-lcairo-gobject \
-lcairo \
-lgdk_pixbuf-2.0 \
-lgio-2.0 \
-lgobject-2.0 \
-lglib-2.0 \
-lserialport
SOURCES += \
main.cpp
———————–main.cpp————————————–
#include
// Callback function for when the selected item in the combo box changes
void on_combobox_changed(GtkComboBox *combobox, gpointer user_data) {
gchar *selected_text = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(combobox));
if (selected_text) {
g_print(“Selected item: %s\n”, selected_text);
g_free(selected_text); // Free the string after use
}
}
// Main function
int main(int argc, char *argv[]) {
GtkWidget *window;
GtkWidget *vbox;
GtkWidget *combobox;
GtkWidget *label;
// Initialize GTK
gtk_init(&argc, &argv);
// Create a new GTK window
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), “GTK ComboBox Example”);
gtk_window_set_default_size(GTK_WINDOW(window), 300, 200);
// Set up a signal handler to exit the program when the window is closed
g_signal_connect(window, “destroy”, G_CALLBACK(gtk_main_quit), NULL);
// Create a vertical box to hold widgets
vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
gtk_container_add(GTK_CONTAINER(window), vbox);
// Create a label
label = gtk_label_new(“Select an item from the combo box:”);
gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 5);
// Create a combo box with text items
combobox = gtk_combo_box_text_new();
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combobox), “Option 1”);
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combobox), “Option 2”);
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combobox), “Option 3”);
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combobox), “Option 4”);
gtk_box_pack_start(GTK_BOX(vbox), combobox, FALSE, FALSE, 5);
// Connect the “changed” signal to the callback function
g_signal_connect(combobox, “changed”, G_CALLBACK(on_combobox_changed), NULL);
// Show all widgets in the window
gtk_widget_show_all(window);
// Enter the GTK main loop
gtk_main();
return 0;
}