2
votes

I'm new to using GTK. Here is a small section of my code. The aim is to copy the entire current line. The contents are stored in "line". "start" and "end" are textiter at start and end of line.

gtk_text_iter_set_line_offset (start, 0); 
gtk_text_iter_forward_to_line_end (end);  
line = gtk_text_iter_get_text (start, end);

gtk_clipboard_set_text (clipboard, line, -1);

And upon execution, Im getting the following error messages.

Gtk[27786]: CRITICAL: gtk_text_iter_set_line_offset: assertion 'iter != NULL' failed
Gtk[27786]: CRITICAL: gtk_text_iter_forward_to_line_end: assertion 'iter != NULL' failed
Gtk[27786]: CRITICAL: gtk_text_iter_get_text: assertion 'start != NULL' failed
Gtk[27786]: CRITICAL: gtk_clipboard_set_text: assertion 'text != NULL' failed

What is wrong with the code block? How can i resolve it? Thanks all :)

1
You give to those functions NULL pointers instead of C strings. Please give more code to understand where is the error.Boiethios
Consider adding how start and end are defined here.sjsam

1 Answers

1
votes

You have probably got your iterators declared like GtkTextIter *start. Instead, according to the text widget conceptual overview in GTK's documentation, "GtkTextIter is a struct designed to be allocated on the stack; it's guaranteed to be copiable by value and never contain any heap-allocated data." This means you should not declare them as pointers:

GtkTextIter start, end;
// ...
gtk_text_iter_set_line_offset (&start, 0); 
gtk_text_iter_forward_to_line_end (&end);  
line = gtk_text_iter_get_text (&start, &end);