Hello people. I have an object_A that has a GtkComboBox and another object_B that has a GtkButton, both are separate files.
I would like to know how do I implement a function in object_B that by clicking on object_B’s GtkButton, object_A’s GtkComboBox performs a certain action. In C language.
That’s more of a question about the C programming language. We’d need to know more, for example, are you using global variables? If that corresponds to your situation you can use the C extern
modifier:
So that would become:
a.c
#include <gtk/gtk.h>
GtkWidget *combo;
int main() {
}
b.c
#include <gtk/gtk.h>
GtkWidget *button;
extern GtkWidget *combo;
void button_clicked(GtkWidget* widget, gpointer user_data) {
/* use combo here */
}
A better solution would be to avoid global variables: pass the data around as function arguments.
a.c
#include <gtk/gtk.h>
#include "b.h"
GtkWidget *combo;
int main() {
combo = gtk_combo_box_new();
/* set up combo box */
create_button(combo);
}
b.h
#include <gtk/gtk.h>
/* function declaration */
void create_button(GtkWidget *combo);
b.c
#include <gtk/gtk.h>
GtkWidget *button
void on_button_clicked(GtkWidget *widget, gpointer user_data) {
GtkWidget *combo = GTK_WIDGET(user_data);
/* use combo here */
}
void create_button(GtkWidget *combo) {
button = gtk_button_new();
/* set up button */
g_signal_connect(button, "clicked", G_CALLBACK(on_button_clicked), (gpointer)combo);
}
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.