Displaying a UTF-8 file in a text view

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
http://mail.gnome.org/mailman/listinfo/gtk-list

[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux