[Glade-users] C Beginner question
Micah Carrick
email at micahcarrick.com
Mon Dec 24 13:33:06 EST 2007
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;
}
- Micah Carrick
Developer - http://www.micahcarrick.com
GTK+ Forums - http://www.gtkforums.com
Lupine wrote:
> Hello list and happy holidays!
>
> I'm not new to Glade, but I am new to C...well sort of. I've played
> with C for a while, but I'm stronger in scripting languages like PHP,
> Perl...etc. However, I wanted to do a comparison of sorts, so I'm
> porting one of my PHP-GTK/Glade apps over to C. In doing so, I'm
> finding the lack of documentation frustrating (simply because I don't
> understand C that well). Can anybody point me to some good
> documentation, besides the Gtk documentation?
>
> For example, I know that I can go here:
> http://www.gtk.org/tutorial/x941.html to see the Gtk way of getting the
> text entered into a GtkEntry. However, how do I do it if I'm using
> Glade. I mean, the autoconnect should already know/create my widget, so
> how do I simply call to the entry?
>
> My GtkEntry widget is called "ssh_user_entry", and my GtkButton is
> called "connect_btn", so I would assume the C/Glade way would be:
>
> 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 */
> gtk_init(&argc, &argv);
> xml = glade_xml_new(GLADE_FILE, NULL, NULL);
> glade_xml_signal_autoconnect(xml); /* connect signal handlers */
> gtk_main();
>
> return 0;
> }
>
> However, this is not working. I keep getting the following error when
> clicking the button:
>
> Gtk-CRITICAL **: gtk_entry_get_text: assertion `GTK_IS_ENTRY (entry)'
> failed
> Entry contents: (null)
>
>
> In PHP-GTK it is MUCH easier, as all I had to do was:
> class phpConnMgr extends GtkWindow
> {
> function __construct()
> {
> $gladefile = $GLOBALS['gladefile'];
> parent::__construct();
> $this->glade = new GladeXML(dirname(__FILE__) . $gladefile);
> $this->glade->signal_autoconnect_instance($this);
> }
>
> function on_connect_btn_clicked()
> {
> $user = $this->glade->get_widget("ssh_user_entry")->get_text();
> echo "$user\n";
> }
> }
> $phpConnMgr = new phpConnMgr();
> Gtk::main();
>
>
>
> If you can let me know the proper way to do this in C/Glade, and/or let
> me know where some simple examples of these common tasks are documented,
> I'd really appreciate it!
>
> Thanks,
> -Lup
>
>
> _______________________________________________
> Glade-users maillist - Glade-users at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/glade-users
>
>
More information about the Glade-users
mailing list