Re: Creating custom GTK+ widget using C++ -- Ctor/Dtor not called

On Thu, Feb 16, 2012 at 04:05:19AM +0530, Agnel Kurian wrote:
> I have implemented a custom GTK+ widget which relies on a C++ object
> internally. i.e. the widget structure contains an instance of a C++ class.
> My concern was that the constructor and destructor of the contained object
> were not being called. I had assumed that merely compiling as C++ would
> make it work... but now I realize it need not be so when allocated via
> g_object_new.

It will not work if you embed the C++ class within the GObject struct
because the GObject struct is simply allocated as a block of memory from
the heap (using GSlice or whatever but anyway no C++ new operator is

You can create C++ objects in the instance-init method of the GObject
and then, for example, put pointers to them to the GObject struct and
destroy them in the the GObject finalize method.

If you just want this and not any of the fancy stuff cxx-gtk-utils does
then it is quite trivial and you do not need any extra library.


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