[SOLVED] GTK with C++ sending multiple GObjects to a callback function through a GObject
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Basically, what I'm doing now is defining a GObject** for the data being sent and assigning a size with g_new(...). Then I am assigning the array elements of my GObject** accordingly and sending it as my data to the callback function.
In the callback function, I assign GObject** data_i_want = (GObject**)data and treat data_i_want as a normal array (so I can access the individual GObject* members as data_i_want[i]).
This is slightly different than what I was going for with g_object_set_data, but it works. If anyone would like to suggest a method for using g_object_set_data, it would still be appreciated.
Does g_object_set_data require memory allocation? In the solution I posted g_new handled that... Also there's no mention of memory allocation for the function documentation.
EntryBoxes is uninitialized so it's pointing to some random block of memory. Attempting to use this pointer will lead to undefined behaviour, such as segfaulting.
Ah, looks like you also need to initialize to a valid GObject value. I'm not really familiar with GTK/Glib stuff, but I think you want something along the lines of
yes but GTK's behavior changes (infact it plain drops support for whole apps to be working any longer)
why not do it the C way, make things simple for poor GTK, give it one object to which you have indexed (by struct offset, or other allocation), your 'stuff'
do be wary under a client/server system there's a difference between memory allocated and accessed on the client, on the server, as transfered and seen between the two. classic mistake
so if i'm using X11 and wish to draw i allocate memory on the server (remote side) and sent draw commands (such as move) and thus, the data in the window does not need to be tranfered to the client for processing and back to the server
also note on broken systems (ie, win32), callbacks are at times done MULTIPLY - so your program should be INDEPENDANT of callbacks (able to avert or handle), and ready to receive a callback during a callback (re-entrant function programming)
So using an array of pointers is a better option then?
I'm mostly doing my window event processing through my callback functions, so if I need to send a draw command to the window then the callback function handles everything I need it to do.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.