gtkgtktextview

Print the text of GtkTextView


How can I print (for example in a label) the text into a GtkTextView? For GtkLabel and GtkEntry there are gtk_label_get_text() and gtk_entry_get_text(), but for GtkTextView?


Solution

  • You can:

    GtkTextIter start, end;
    GtkTextBuffer *buffer = gtk_text_view_get_buffer (text_view);
    gchar *text;
    
    gtk_text_buffer_get_bounds (buffer, &start, &end);
    text = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
    

    Don't forget to g_free (text) when no longer needed.