views:

28

answers:

2

So I'm trying to make use of a GtkSourceView in C++ using GtkSourceViewmm, whose documentation and level of support give me the impression that it hasn't been very carefully looked at in a long time. But I'm always an optimist :)

I'm trying to add a SourceView using some code similar to the following:

 Glib::RefPtr<gtksourceview::SourceLanguageManager> source_language_manager = gtksourceview::SourceLanguageManager::create();
 Glib::RefPtr<gtksourceview::SourceLanguage> source_language = Glib::wrap(gtk_source_language_manager_guess_language(source_language_manager->gobj(), file, NULL));
 Glib::RefPtr<gtksourceview::SourceBuffer> source_buffer = gtksourceview::SourceBuffer::create(source_language);
 gtksourceview::SourceView* = m_source_view = new gtksourceview::SourceView(source_buffer);

 m_vbox.pack_start(*m_source_view);

Unfortunately, it spits out the warning

(algoviz:4992): glibmm-WARNING **: Failed to wrap object of type 'GtkSourceLanguage'. Hint: this error is commonly caused by failing to call a library init() function.

and when I look at it in a debugger, indeed the second line above (the one with the Glib::wrap()) is returning NULL. I have no idea why this is, but I tried to heed the warning by adding Glib::init() to the begining of the program, but that didn't seem to help at all either.

I've tried Google'ing around, but have been unsuccessful. Does anyone know what Glib wants me to init in order to be able to make that wrap call? Or, even better, does anyone know of any working sample code that uses GtkSourceViewmm (not just regular GtkSourceView)? I haven't been able to find any actual sample code, not even on Google Code Search.

Thanks!

A: 

I use gtkmm. Typically you have to initialize things with something like :

_GTKMain = new Gtk::Main(0, 0, false);

Of course do not forget :

delete _GTKMain;

Check here for details :

http://library.gnome.org/devel/gtkmm/2.19/classGtk_1_1Main.html

(Sorry but the link option does not work ...)

neuro
You linked to the exact same question you were answering =P
Adrian Petrescu
@Adrian: yes, you are right. I corrected that, thank you :-)
neuro
Hehe, no problem :) But I was already doing this (I don't think the window would have even showed up if I had missed starting the main loop!) The problem was something else, which I posted in my own answer.Thanks for your answer, though!
Adrian Petrescu
Ok. No problem.
neuro
+2  A: 

It turns out, perhaps not surprisingly, that what I needed to init was:

gtksourceview::init();

After this, I ran into another problem with one of the parameter to gtksourceview::SourceLanguageManager, but this was caused by a genuine bug which I subsequently reported and was promptly fixed. So everything's working great now!

Adrian Petrescu