c++ objects



I'm a gtk newbie and figured it would be nicer to work with actual c++ objects than it would be to use the native C library object implementation, so I started learning gtkmm.
I came across a problem, and I see others have the same question and I think I understand but I just wanted to run it by you guys make sure I'm not missing something.

I use gtkbuilder because it's so freakin awesome and that's really how it should be done, and in one line of code BOOM my entire UI shows up on the screen. Perfect.

I have to do some signal binding, but after that all is well.

But there are places where you need the object that or more importantly need to subclass the object that gtkbuilder made and you can't.
I found 2 cases so far:

1) If I wanted to be all C++ happy and make my "DoSomething" button widget have a handlebuttonclick() method in the class representing the button, I can't, because glade has no idea such a class exists it only makes the standard built-in widgets, and I'm forced to use a global function to handle the click signal.
I've seen examples of how to do this in gtkmm but they're all without using gtkbuilder, so they can define their classes at compile time and everything's available at build time.

2) I want to make a list box, so I make a treeview and in glade I define a ListStore for it and it all comes up nice, but when I want to add to it, I have to create the C++ object representing the ListStore object so that I can add it, and I can't pull it out of gtkbuilder for a similar reason as #1: at compile time, the compiler can't possibly know about what gtkbuilder is going to do at runtime, so I can't code an add of an object that nobody defined for the compiler at compile time.
It's the same problem this guy had:  http://old.nabble.com/TreeModel-with-Gtk::Builder-td23419723.html

Alternatively for #1 I can define my own widget for glade which includes my extra handlebuttonclick() method and glade will let me use it in design and gtkbuilder will make one. I haven't tried it but it makes sense and from what I've read sounds possible, but to me it seems a bit overkill just to be C++ happy. So I stick with the global function

For #2 there must be some kind of internal structure gtkbuilder uses to render the list box because glade lets me define the structure of the ListStore. I imagine that internally it is just a dynamic data structure of some kind. I obviously couldn't use it natively in C++, but maybe I could use it to add items to my list anyway. Suggestions?

Anyway, I'm not complaining or asking anybody to change things, I just want to make sure my understanding is correct. Does the above make sense to everybody or am I off the mark somewhere?

Thanks.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]