views:

122

answers:

1

I'm just learning about gtkmm for c++. I'm having trouble getting a simple TextBuffer to add a new line of text. I have a class called OutputBox which is an HBox with a TextViewer (called messages) and a TextBuffer (called textBuffer) in it.

Here is a small chunck of the OutputBox class:

OutputBox::OutputBox() {
  textBuffer = messages.get_buffer();
};

void OutputBox::addText( string newText) {
  textBuffer->insert(textBuffer->begin(), newText);
};

Now I expect that when I pass a string into addText, the new string will be added to the buffer, but instead I get a seg fault.

After running it through gdb, I see that the error comes from the gtkmm libraries here:

template <class T_CppObject> inline
T_CppObject* RefPtr<T_CppObject>::operator->() const
{
  return pCppObject_;
}

I'm not really sure what this is telling me either. I assume that I'm incorrectly using the class.

+1  A: 

I would advise attaching a debugger to see where the fault occurs.

If it occurs within GTKmm libraries, then you are probably using the API incorrectly. If it occurs in your code then it will point you in the right direction

:)

Aiden Bell