1

I'm using anjuta with glade and gtk+.

I'm trying to get the button in my app to change the window title:

void changetitle(GtkWidget *win)
{
gtk_window_set_title(GTK_WINDOW(win),"My Window"); 
    FILE *fh = fopen("/tmp/output.txt", "w");
  fclose(fh);
}

I'm trying to get the button to execute this action, but I seem to be failing with passing the window as an argument.

Here's what I've tried:

enter image description here

the second function (creating the file) seems to work.

user12205
  • 2,566
  • 1
  • 17
  • 37
Adel Ahmed
  • 518
  • 5
  • 23

1 Answers1

1

From the GTK+ 3 Reference Manual:

The “clicked” signal

void
user_function (GtkButton *button,
               gpointer   user_data)

This means that, when the callback function is called, the first argument passed to it will be the button, not the window.

To fix this, you have two options:

You can either change changetitle to the following:

void changetitle(GtkButton *button, gpointer win) { //...

Or (i.e. don't do both together), in Glade when you connect the signal, check the "swap" box:

screenshot: connect "swap" button in Glade

By doing so, the order of the parameters will be swapped, so the first parameter will be your specified data (i.e. the window), and the second parameter (which isn't specified in your callback function and hence will not matter) will be your button.

user12205
  • 2,566
  • 1
  • 17
  • 37