tags:

views:

86

answers:

1
GtkWidget *textview;
...
textview = gtk_text_view_new ();
...
buffer = gtk_text_view_get_buffer (textview);

At the last line I pasted I got this warning:

warning C4133: 'function' : incompatible types - from 'GtkWidget *' to 'GtkTextView *'

How can I fix that?

+2  A: 

In GTK/GLib/GObject, each class has a typecast macro (the name of the class in uppercase, with underscores) which also checks that the object is of the requested class. Also, most constructors in GTK return GtkWidget * pointers, so you have to cast them.

Either of these will work:

1.

GtkWidget *textview;
textview = gtk_text_view_new();
buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview));

2.

GtkTextView *textview;
textview = GTK_TEXT_VIEW(gtk_text_view_new());
buffer = gtk_text_view_get_buffer(textview);
ptomato