[Glade-users] How to compare "entry" input to string?

Tristan Van Berkom tvb at gnome.org
Mon Nov 7 11:17:09 EST 2005


Bob Jones wrote:
> I'm trying to compare an "entry" to a string with the
> following:
> 
> GtkWidget * entry = lookup_widget(GTK_WIDGET(button),
> "entry2");
> if(entry=="Test")
> {
>   g_print("Comparison triggered.");
> }

In the C programming language, you need to use a function
call to compare charachter arrays (strings).

The statement here `entry == "Test"' will only be true
if the address of the entry widget is the same address
of the first letter "T" in your string constant.

What you need to do first is retrive the current text
buffer from the entry widget (probably with a function like
gtk_entry_get_text(), see API docs to be sure), and then
compare the text buffer with your string constant with
a function like strcmp().

=============================================================
GtkWidget *entry = lookup_widget(GTK_WIDGET(button), "entry2");
gchar     *text  = gtk_entry_get_text (GTK_ENTRY (entry));

if (!strcmp (text, "Test"))
{
     g_print("Comparison triggered.");
}
=============================================================

Cheers,
                          -Tristan


More information about the Glade-users mailing list