Search code examples
cgtkglade

Glade3 C Programming Buttons


I'm very unaware of how the syntax goes for GTK+Glade3 programming. But for now I'm trying to experiment and making a simple program that changes text when I click a button

void on_CLICK_clicked (GtkButton *button, gpointer user_data)
{
    GtkWidget *text = lookup_widget(GTK_WIDGET(button), "entry1");
    gtk_entry_set_text(GTK_WIDGET(text), "Hello");
}

I have these alarming errors that I don't know how to solve:

implicit declaration of function 'lookup_widget' [which also explains the undefined reference to 'lookup_widget']

passing argument 1 of gtk_entry_set_text' from incompatible pointer type


Solution

  • lookup_widget() was only used in Glade 2's generated code. Glade 2 used to generate a file, support.c, that contained that function and other ones. This is not used anymore. You can now specify the entry widget as the user data parameter when you connect the clicked signal in Glade 3, so you can do the following:

    void on_CLICK_clicked (GtkButton *button, GtkEntry *text)
    {
        gtk_entry_set_text(text, "Hello");
    }
    

    The second warning was caused by you casting text to a GtkWidget * and then passing it to gtk_entry_set_text() which expects a GtkEntry *. The proper syntax would have been GTK_ENTRY(text), but you don't need to do that anymore since you already have a GtkEntry * pointer in the code I wrote above.