[Glade-users] How to compare "entry" input to string?
- From: tvb at gnome.org (Tristan Van Berkom)
- Subject: [Glade-users] How to compare "entry" input to string?
- Date: Mon Nov 7 10:26:02 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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]