I am using this code:
class editbook
{
GtkWidget* _nbook;
std::vector<GtkWidget*> _srcset; //and so on...
...........................................................................................
void editbook::add_page()
{
GtkWidget* tmp = gtk_source_view_new();
_srcset.push_back(tmp);
gtk_notebook_append_page(GTK_NOTEBOOK(_nbook),tmp,gtk_label_new("untitled"));
}
...........................................................................................
void editbook::set_text(const std::string& text)
{
int index = gtk_notebook_get_current_page(GTK_NOTEBOOK(_nbook));
GtkTextBuffer* tbuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(_srcset[index]));
gtk_text_buffer_set_text(GTK_TEXT_BUFFER(tbuffer),text.c_str(),-1);
}
Compiles fine. But gives this weird runtime error:
Segementation Fault: return 139
I have traced down the problem to: gtk_text_view_get_buffer(GTK_TEXT_VIEW(_srcset[index]));
NOTE: I am using GtkSourceView instead of GtkTextView, but that may not be a problem because I am gettin the same error when I try GtkTextView.
NOTE: I am using Gtk 2x
NOTE: I am not sure whether to tag this question with C or C++. bec. Gtk+ is a C lib. But I am using C++. So I'll just tag both for now.
_srcsetarray? Btw why don't you useGtkMM( gtkmm.org/en ) which is C++ wrapper overGtkin case you want to write your code in C++?std::vector<GtkWidget*> _srcset. Filled with GtkSourceViews (gtk_source_view_new()); As for GtkMM. Frankly I don't use it because I am an idiot... And because It doesn't compile on Ubuntu for some reason (glibmmconfig.h not found)_srcset[index]must be a valid reference at the time of execution.NULL& if they are valid objects? I mean what is the output forGTK_IS_TEXT_VIEW(_srcset[index])>K_IS_TEXT_BUFFER(tbuffer)? Also, I would suggest you please usevector::atinstead ofoperator[]just to be sure that you are not going out of the range.