Re: Casting GtkWidgets



Naheed Vora wrote:

void
on_combo_entry1_activate               (GtkEditable     *editable,
                                        gpointer         user_data)
{

GtkWidget *text_entry = user_data;
char *string = gtk_entry_get_text(GTK_ENTRY (text_entry));
g_print(string);

}


this should be:

void on_combo_entry1_activate(GtkEditable *editable,gpointer user_data)
{
  gchar *string = gtk_entry_get_text(GTK_ENTRY(user_data));
  g_print(string);
}

or:

void on_combo_entry1_activate(GtkEditable *editable,gpointer user_data)
{
  GtkWidget *entry = GTK_WIDGET(user_data);
  gchar *string = gtk_entry_get_text(GTK_ENTRY(entry));
  g_print(string);
}

or:

void on_combo_entry1_activate(GtkEditable *editable,gpointer user_data)
{
  GtkWidget *entry = (GtkWidget*)user_data;
  gchar *string = gtk_entry_get_text(GTK_ENTRY(entry));
  g_print(string);
}


that all does the same...

Gtk-WARNING **: invalid cast from (NULL) pointer to `GtkEntry'

that's true, because a gpointer is really a void*, and you can't
reference a pointer to something of type void.

Please guide me how can I cast the gpointer into char* which is recieved
from signal caused by Gtk_entry widget.

oh, but is the gpointer a string or a pointer to an entry widget?
because if it's a string then you should do:

void on_combo_entry1_activate(GtkEditable *editable,gpointer user_data)
{
  gchar *string = (gchar*)user_data;
  g_print(string);
}

but I guess that user_data is a pointer to a widget?
you could just use the editable...

void on_combo_entry1_activate(GtkEditable *editable,gpointer user_data)
{
  gchar *string = gtk_editable_get_chars(editable,0,-1);
  g_print(string);
}

have fun...

Willem

-- 
wrvh xs4all nl         | http://www.xs4all.nl/~wrvh
wrvhage science uva nl | http://quest.sourceforge.net





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]