GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sat Jul 26, 2014 3:10 pm

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: gtk_drawing_area_size first parameter
PostPosted: Fri Jul 13, 2012 7:28 pm 
Offline

Joined: Fri Jul 13, 2012 7:18 pm
Posts: 1
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
Code:
#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

Code:
gtk_drawing_area_size(G_OBJECT(drawingArea),200,200);

the error when compiling
Code:
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


Top
 Profile  
 
 Post subject: Re: gtk_drawing_area_size first parameter
PostPosted: Fri Jul 13, 2012 8:38 pm 
Offline
Familiar Face

Joined: Thu Dec 15, 2011 6:23 pm
Posts: 36
Location: Hrvatska
hi and welcome.

is there any particular reason to work with GTK+ 2 ?
GTK+ 3 is not NEW any more, it is stable and much better.
please, think of it.

gtk_drawing_area_size is deprecated, but if you insist - do not use G_OBJECT modifier.

I use fedora linux and got DEVHELP application with complete GTK documentation. If you cant find such application, you can allways go to web page with documentation for API function prototype.

Cheers !


Top
 Profile  
 
 Post subject: Re: gtk_drawing_area_size first parameter
PostPosted: Fri Jul 13, 2012 10:31 pm 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 733
Location: UK
Hi,

There could be several reasons to still be using GTK+ v2. Some Linux distributions do not have GTK+ v3 yet in their stable release. Also there is not a bundled version of GTK+ v3 for Windows as of yet. It is still advisable to avoid the use of deprecated API calls so that when the need to convert to GTK+ v3 happens it can then be done with ease.

As already noted gtk_drawing_area_size() is deprecated and you should be using gtk_widget_set_size_request () instead.

The reason the code failed to compile is that the first argument of gtk_drawing_area_size() is of type GtkDrawingArea* and you are passing it a GObject* which are not the same.

Also the final argument to g_signal_connect() is a pointless bit of extra code and you could pass NULL instead.

_________________
E.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group