TextView doesn't show text after buffer change



Hello,
I am starting out with gtkmm and was trying to load some text to a TextView which has already been "shown" (with textview1->show()). So I've done something like the following:

Glib::ustring *lineOfText = new Glib::ustring("new text");
Glib::RefPtr<Gtk::TextBuffer> buffer = textview1->get_buffer();
buffer->set_text(*lineOfText);

But the text won't show up in the textview. However the buffer seems to be updated properly, as something like

std::cout << buffer->get_text() << std::endl;

correctly shows "new text" in the terminal. I would really appreciate any help on this. Also is there a way to append to a buffer? I've tried

Gtk::TextBuffer::iterator iter = buffer->end();
buffer->insert(iter, *lineOfText);

but this gives me a warning

Gtk-WARNING **: Invalid text buffer iterator: either the iterator is uninitialized, or the characters/pixbufs/widgets in the buffer have been modified since the iterator was created. You must use marks, character numbers, or line numbers to preserve a position across buffer modifications.
You can apply tags and insert marks without invalidating your iterators,
but any mutation that affects 'indexable' buffer contents (contents that can be referred to by character offset)
will invalidate all outstanding iterators

plus the same problem as above. Nothing shows up on the textview.

Thank you for you patience,
Spyros S.



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