0

I have a custom GTK+ widget which I am compiling in a C++ file (instead of C). Most of the code is the C subset of C++. The application seems to run fine. (Right now it merely displays a top-level window with the widget in it.) However, I have included a destructor in the widget structure and noticed that the destructor is never called.

  • What should I do (short of using gtkmm) in order to ensure that the destructor is called?
  • What are the other consequences I should be aware of when implementing a GTK+ widget in C++?

1 Answer 1

1

GTK uses object oriented C, where the Object oriented part is visualized using function pointers. so if you can cache your this pointer with C side code of gtk widget, then here is more info...

if you are running out of time, then take a review of this example... Look for gtk_cpu_destroy in this example, the following code set the function pointer in widget.

object_class->destroy = gtk_cpu_destroy;

beside gtkmm, there also exist gfc project, which i think is cleaner, and easier to understand...

What are the other consequences I should be aware of when implementing a GTK+ widget in C++?

my query is if your custom widget is really gtk widget or gdk widget... not all events of gdk are handled in gtkmm(or at least they were not back in 2009), thus beware that your application may crash too often, if your widget is extensively using gdk, and gdk events are not trapped. tools like systemtap might help you to trap the events causing problem.

Sign up to request clarification or add additional context in comments.

4 Comments

This is a GTK+ widget using Cairo for drawing. I am compiling as a C++ instead of a C.
Gfc isn't an option for anyone, last release was 2004.
yep gfc is not an option anymore, yet a good option for looking inside code to understand the OOC integration with c++... #Agnel With Cario, you will not face those crashes, i also shifted to cairo last time when i did the custom widgets..
@PM, There is no crash. Just a destructor which is not being called.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.