[Glade-users] C Beginner question
Lupine
thelupine at gmail.com
Mon Dec 24 20:47:15 EST 2007
On Mon, 2007-12-24 at 10:33 -0800, Micah Carrick wrote:
> Did you specify "ssh_user_entry" as the user_data for the "clicked"
> event of the button in the glade file? Otherwise, you might want to use
> glade_xml_signal_connect instead of autoconnect so you can specify the
> user data. Sometimes if you have custom user data, you use
> glade_xml_signal_connect_data for your connections instead.
>
> void on_connect_btn_clicked(GtkButton *button, GtkWidget
> *ssh_user_entry)
> {
> const gchar *ssh_user_text;
> ssh_user_text = gtk_entry_get_text (GTK_ENTRY (ssh_user_entry));
> printf ("Entry contents: %s\n", ssh_user_text);
> }
>
> int main (int argc, char *argv[])
> {
> GladeXML *xml; /* glade xml file */
> GtkWidget *entry;
>
> gtk_init (&argc, &argv);
> xml = glade_xml_new (GLADE_FILE, NULL, NULL);
>
> /* get a reference to the entry widget */
> entry = glade_xml_get_widget (xml, "ssh_user_entry");
>
> /*
> assumes "on_connect_btn_clicked" is the handler name specified in glade
> and passes the entry widget as user data.
> */
>
> glade_xml_signal_connect_data (xml,
> "on_connect_btn_clicked",
> G_CALLBACK (on_connect_btn_clicked),
> entry);
>
> /*
> unlike PHP, you're responsible for freeing memory with C
> Below we are unreferencing the xml object in memory now that we've built
> the UI and obtained references to the widgets we need.
> */
>
> g_object_unref (xml);
>
> gtk_main();
>
> return 0;
> }
Ahhh, thanks for the thorough explanation, and sample code. It makes a
little more sense now. I'm just a little confused on the format of the
glade_xml_signal_connect_data function. I'm now wondering how the best
way to pass multiple GtkEntry inputs to that function, or do I go and
grab that information from within the void on_connect_btn_clicked()
function.
Is there any site that I can reference for future, similar, basic
questions?
Thanks again for the same-day response!
-Lup
More information about the Glade-users
mailing list