开发者

What's the solution for this gtk warning?

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 C4开发者_高级运维133: 'function' : incompatible types - from 'GtkWidget *' to 'GtkTextView *'

How can I fix that?


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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜