Implementing GObject Interface in C ++

I am trying to implement the GType interface in C ++ using Glibmm (part of Gtkmm). The object will be passed to the API in C. Unfortunately, the documentation for gtkmm does not cover many details of how it wraps the GObject system.

What I still have:

class MonaCompletionProvider : public gtksourceview::SourceCompletionProvider, public Glib::Object { public: MonaCompletionProvider(); virtual ~MonaCompletionProvider(); Glib::ustring get_name_vfunc() const; // ... and some more } 

All implementations of the method and constructor are empty. The code is used as follows:

 Glib::RefPtr<MonaCompletionProvider> provider(new MonaCompletionProvider()); bool success = completion->add_provider(provider); 

success will be false after executing this code, and the following message will appear on the command line:

(monagui: 24831): GtkSourceView-CRITICAL **: gtk_source_completion_add_provider: statement `GTK_IS_SOURCE_COMPLETION_PROVIDER (provider)" failed

It seems that the underlying gobj() does not know that it should implement this interface. If the class fails from Glib::Object , gobj() even returns null. I hope I don't need to write a GObject that implements this interface in C manually.

So what is the right way to do this? Thanks in advance.

PS: For those interested: SourceCompletionProvider

+6
c ++ glib gtkmm
source share
1 answer

Finally, I found a solution.

Class definition (subclass order):

 class MonaCompletionProvider : public Glib::Object, public gtksourceview::SourceCompletionProvider { ... 

Constructor (again, order matters):

 MonaCompletionProvider::MonaCompletionProvider() : Glib::ObjectBase(typeid(MonaCompletionProvider)), Glib::Object(), gtksourceview::SourceCompletionProvider() { ... 

The solution was found by checking how it was done in Guikachu .

+5
source share

All Articles