Re: C++ and gobject



On Fri, 2015-12-18 at 10:37 -0800, Andy Tai wrote:
Hi, this is a general question on C++ and gtk+, or actually gobject. 
I believe that gtkmm is still more or less manually maintained over
the gtk+ API.

It's mostly generated. We define the API and the implementation is
mostly generated.

The question is, gobject now has gobject insepction that supposelyl
allows automatic binding of different languages to the gobject based
APIs.  Can that be used to create a C++ wrapper for gobject
libraries?  Say a C++ header file for static compiling of C++ code
using gtk+.  (Is it possible?  Maybe not optimal?)

We use .defs files now. GObject introspection provides a little more
information that would be useful, so we could use that instead to get
the information about the API. But nobody has spent the time to do
that. The advantage would be fairly minimal. Patches are very welcome.

We wouldn't want to stop having control over the actual API that we
provide. It's not possible to generate a good C++-specific API unless
we don't care about the quality of that API.

Another question is that, is it possible to create wrappers to make
C++ classes to appear as gobject classes so one can use C++ to
implement base classes that can then be wrapped in gobject classes
for interaction with other gobjects?

Yes. Via Glib::wrap() and gobj(). For instance, there's nothing unusual
about putting a Gtk::Widget inside a GtkContainer. You just call gobj()
on the Gtk::Widget to get the underlying GObject from the GtkWidget.

But this is not wrapping a C++ object in a C object. Instead, the C++
object has a C object which you may use.

-- 
Murray Cumming
murrayc murrayc com
www.murrayc.com





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