I try to implement a GType interface in C++ using Glibmm (part of Gtkmm). The object will be passed to an API in C. Unfortunately, the documentation for gtkmm does not cover many details of how it wraps the GObject system.
What I have so far:
class MonaCompletionProvider : public gtksourceview::SourceCompletionProvider, public Glib::Object
{
public:
MonaCompletionProvider();
virtual ~MonaCompletionProvider();
Glib::ustring get_name_vfunc() const;
// ... and some more
}
All method and constructor implementations are empty. The code is used like this:
Glib::RefPtr<MonaCompletionProvider> provider(new MonaCompletionProvider());
bool success = completion->add_provider(provider);
success
will be false after executing this code and the following message appears in the command line:
(monagui:24831): GtkSourceView-CRITICAL **: gtk_source_completion_add_provider: assertion `GTK_IS_SOURCE_COMPLETION_PROVIDER (provider)' failed
It seems that the underlying gobj()
is not aware that it is supposed to implement this interface. If the class does not derive from Glib::Object
, gobj()
even returns null. I hope that I do not have to write a GObject implementing this interface in C manually.
So what is the correct way to do this? Thanks in advance.
PS: For those who are interested: SourceCompletionProvider
Finally, I found a solution.
Class definition (order of subclasses matters):
class MonaCompletionProvider : public Glib::Object, public gtksourceview::SourceCompletionProvider {
...
Constructor (again, order matters):
MonaCompletionProvider::MonaCompletionProvider() :
Glib::ObjectBase(typeid(MonaCompletionProvider)),
Glib::Object(),
gtksourceview::SourceCompletionProvider() {
...
Solution found by inspecting how it has been done in Guikachu.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With