Hello guys I’m using C and GTK+ 2 I want to make a simple paint program like MS program but by these two tools only okay I just started and I want your hands to reach the end 🙂
look to my code here
#include <gtk/gtk.h>
int main(int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *drawingArea;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_signal_connect(G_OBJECT(window), "delete_event",
G_CALLBACK(gtk_main_quit), G_OBJECT(window));
g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit),
G_OBJECT(window));
gtk_container_set_border_width(GTK_CONTAINER(window), 10);
drawingArea = gtk_drawing_area_new();
/*The problem is in the next line */
gtk_drawing_area_size(G_OBJECT(drawingArea), 200, 200);
gtk_container_add(GTK_CONTAINER(window), drawingArea);
gtk_widget_show(drawingArea);
gtk_widget_show(window);
gtk_main();
return 0;
}
my problem is in the commented line
gtk_drawing_area_size(G_OBJECT(drawingArea),200,200);
the error when compiling
ibrahim@ibrahim-PC:~/Desktop$ gcc main.cpp -o base `pkg-config --cflags --libs gtk+-2.0`
main.cpp: In function ‘int main(int, char**)’:
main.cpp:14:52: error: cannot convert ‘GObject* {aka _GObject*}’ to ‘GtkDrawingArea* {aka _GtkDrawingArea*}’ for argument ‘1’ to ‘void gtk_drawing_area_size(GtkDrawingArea*, gint, gint)’
So Please help me
That’s a common gotcha in GTK+. You have to cast the widget to the type that exposes the method (i.e. the implementing type). You should write:
Instead of:
Because the GObject type does not support the gtk_drawing_area_size() method, but the GtkDrawingArea type does.
(Actually, it’s more like
gtk_drawing_area_size()does not support taking aGObjectinstance, since GTK+’s object oriented nature is abstracted that way in C.)