开发者

What's the solution for this gtk warning?

开发者 https://www.devze.com 2022-12-28 16:57 出处:网络
GtkWidget *textview; ... textview = gtk_text_view_new (); ... buffer = gtk_text_view_get_buffer (textview);
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

精彩评论

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