Re: Can't get text from entry
- From: shakti <shprasad novell com>
- To: César Leonardo Blum Silveira <cesarbs brturbo com>
- Cc: gtk-app-devel <gtk-app-devel-list gnome org>
- Subject: Re: Can't get text from entry
- Date: Tue, 14 Dec 2004 10:49:35 +0530
Hi,
This piece of code gave segfault to me.
Make the changes:
César Leonardo Blum Silveira wrote:
Why doesn't the following piece of code work?
#include <gtk/gtk.h>
char *string=NULL;
void combo_change(GtkWidget *widget, gpointer data)
{
gchar *selected;
selected = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(widget)->entry));
selected = gtk_entry_get_text (GTK_ENTRY (widget));
strcpy(string, selected);
memory allocation is not done for string.
printf("%s\n",string);
Comment it out and put printf ("%s\n", selected);
}
int main(int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *combo;
GList *opt;
GList *opt = NULL;
gtk_init(&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
combo = gtk_combo_new();
opt = g_list_append(opt, "string 1");
opt = g_list_append(opt, "string2");
gtk_combo_set_popdown_strings(GTK_COMBO(combo),opt);
g_signal_connect(G_OBJECT(GTK_COMBO(combo)->entry),"activated",G_CALLBACK(combo_change),NULL);
g_signal_connect (G_OBJECT (GTK_COMBO (combo)->entry), "changed",
G_CALLBACK (combo_change), NULL);
It will work.
Thanks,
Shakti
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]