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 Aug 27, 2016 1:09 am

All times are UTC

Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Best Practices
PostPosted: Thu Nov 28, 2013 5:39 am 

Joined: Wed Nov 27, 2013 2:11 am
Posts: 2
Hi everyone,

I have a question about the widgets that represent a full application and callbacks. From my understanding, a callback takes a gpointer which can either be a single widget or a structure that contains several of them. I have some design issues where I'm trying to update parts of my UI that have nothing to do with any specific callback. For example, disabling some menu options when some other widget gets activated or deactivated. To me this sounds like I need to have the widgets that represent my application in a global structure so other callbacks can access the parts they need. Is this considered the best way to do things?
Here's what I mean:

typedef struct Application {
   /* a bunch of widgets for the UI */
} Application;

   Application *app = g_new(Application, 1);
   /* the callback below only has access to the single widget passed
       but if it's a structure then it has access to everything.  If this one
       widget gets passed to another function inside the callback, then that function
       loses access to the other parts of the user interface too.  Do I just
       pass the entire structure all the way down the call chain? */

   g_signal_connect(object, "signal", G_CALLBACK(callback), some_widget);

I'm sure we have some veterans on these forums and I haven't studied event-based systems in school yet just on my own. What's your take?


 Post subject: Re: Best Practices
PostPosted: Thu Nov 28, 2013 8:46 pm 
Familiar Face

Joined: Wed Jul 03, 2013 4:52 am
Posts: 9
Another way to do it is to use g_object_set_data() to add a pointer to an object. For example you could add a pointer to another object to your main window object and by passing a pointer to the main window to functions you can access other objects by using g_object_get_data().

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC

Who is online

Users browsing this forum: No registered users and 6 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