Re: Casting GtkWidgets



On Thu, 05 Oct 2000 01:05:17 Willem Robert van Hage wrote:
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.


Ahum, this is not true, it says there's an invalid cast, not a reference,
He just saying something like:

entry = (GtkWidget*)user_data, where user_data == NULL. The GTK_WIDGET
macro checks this , and displays the error message shown

You're right you can't refenence are void*, however this is not being done
here. (The * is within the (), so it's just a cast from void* (the
gpointer) to GtkWidget*, just another pointer.

Also in the Gtk Api reference one can read that gtk_entry_get_text is
deprecated. gtk_editable_get_chars schould be used instead.

Jeroen




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