问题
I am trying to draw a scatterplot with cairo in gtk3. To start, I am using the examples here: http://zetcode.com/tutorials/cairographicstutorial/
They compile with gtk2 successfully but display no image. They do not compile with gtk3 but give the following error:
example.c: In function ‘on_expose_event’:
example.c:17:31: error: ‘GtkWidget’ has no member named ‘window’
Any help on this would be greatly appreciated.
btw I am using writing using ArchLinux for this if that helps.
回答1:
There have been quite a few changes in Gtk3. There is no member window
exposed as part of GtkWidget
anymore, the members have been moved to GtkWidgetPrivate
which is an opaque structure so you cannot access the members directly from GtkWidget
. You will have to use accessor function, in this case where you need window
member of GtkWidget
you can use gtk_widget_get_window, but that may not fix the code sample with which you are working. Please note that the expose_event
signal has been replaced with draw
signal so you will need to update the function which is actually drawing appropriately (on_expose_event
in your case I think). Please refer this link to see the list of changes needed to switch to Gtk3. You can refer source provided by gtk-demo
application or demos/gtk-demo
from Gtk3 source code to get sample code.
Regarding image not being shown in case of Gtk2, if you are working with image sample, please make sure that the image file is available in the path mentioned in the source.
Hope this helps!
来源:https://stackoverflow.com/questions/8722084/using-cairo-with-gtk3