Displaying a UTF-8 file in a text view
- From: Kumar Appaiah <akumar iitm ac in>
- To: gtk-list gnome org
- Subject: Displaying a UTF-8 file in a text view
- Date: Sun, 25 Feb 2007 03:58:57 +0000 (UTC)
Dear GTK+ users,
I am trying to display a UTF-8 file in a very simple GTK+ application using a
text view. Now, am sure that other things with my setup are fine, since gedit
displays the file with no problems. However, my application gives the following
error:
(llf_utf:8373): Gtk-CRITICAL **: gtk_text_buffer_emit_insert: assertion
`g_utf8_validate (text, len, NULL)' failed
The relevant part of the code is:
<code>
gchar *buf, *actualText;
gsize n_read, n_written;
GtkTextBuffer *textBuffer = NULL;
gsize n;
g_file_get_contents(filename, &buf, &n, NULL);
actualText = g_convert((const gchar *)buf, (gssize) n,
"UTF-8",
"ISO8859-1",
&n_read,
&n_written,
NULL);
textBuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textarea));
gtk_text_buffer_set_text(GTK_TEXT_BUFFER(textBuffer),
actualText, n);
</code>
What could the mistake be? How do I read the UTF-8 file?
Thanks.
Kumar
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]