I am new to GTK and so, after making some example programs found online, I am trying to make my own.
I wish to use Glade to develop the GUI, and C++ behind the scenes.
I am using Glade version 3.8.0, and Ubuntu Linux
For my first program I have made a GUI in Glade which consists of two text entry boxes, a button, and a label. The ultimate aim is for a user to enter numbers into each of the text boxes, press the button, and the result of their addition is displayed in the label.
To start with I just wish to get a 'reaction' from my button....
Here is my code, cobbled together through my understanding of examples online.......
using namespace std;
/* store the widgets which may need to be accessed in a typedef struct */
gboolean init_app (MyStruct *MyProg);
void on_button1_clicked (GtkButton *button)
cout << "hello!" << endl;
int main (int argc, char *argv)
MyProg = g_slice_new (MyStruct);
/* initialize GTK+ libraries */
gtk_init (&argc, &argv);
if (init_app (MyProg) == FALSE) return 1; /* error loading UI */
/* show the window */
/* enter GTK+ main loop */
g_slice_free (MyStruct, MyProg);
gboolean init_app (MyStruct *MyProg)
/* use GtkBuilder to build our interface from the XML file */
builder = gtk_builder_new ();
gtk_builder_add_from_file (builder, "experiment.glade", NULL);
/* get the widgets which will be referenced in callbacks */
MyProg->window = GTK_WIDGET (gtk_builder_get_object (builder, "window1"));
MyProg->button = GTK_WIDGET (gtk_builder_get_object (builder, "button1"));
gtk_builder_connect_signals (builder, MyProg);
/* free memory used by GtkBuilder object */
g_object_unref (G_OBJECT (builder));
I am compiling it using this command:
g++ -Wall -g -export-dynamic -o experiment `pkg-config --cflags --libs gtk+-2.0 libglade-2.0` experiment.cpp
As it stands the program runs and my GUI appears on the screen. Unfortunately it is accompanied by a message in the console,
Gtk-WARNING **: Could not find signal handler 'on_button1_clicked'
I set this signal handler in Glade in the properties window. My understanding is that as long as I use the same function name in my code then it should be able to find it?
What am I doing wrong?
Thanks for any guidance