I have a struct that i populate to update my textview widget (note i am mixing C and C++ code, and my compiler is g++)
struct wdata
{
// some other variables;
// assume all the widget are initiated properly
struct *GUI { all the widgets...};
const char* psText , *csText;
}
In a thread (different from gtk_main thread), after certain messages are received ...the status is reported in a texview, and because it is running in a different thread, i use gdk_threads_add_idle()
wd->csText = convChar(" Valid message : Ok... \n");
gdk_threads_add_idle(disptext_CS,(void*)wd);
where the methods convChar()
and disptext_CS
are follow:
const gchar* convChar(string sc)
{
return sc.c_str();
}
and
gboolean disptext_RFCS(void* wdata)
{
WinData* wd = (WinData*)wdata;
wd->GUI->mark = gtk_text_buffer_get_insert(wd->GUI->buffview);
gtk_text_buffer_get_end_iter(wd->GUI->buffview, &wd->GUI->iter);
gtk_text_buffer_move_mark(wd->GUI->buffview, wd->GUI->mark,
&wd->GUI->iter);
gtk_text_buffer_insert_at_cursor(wd->GUI->buffview, wd->csText, -1);
gtk_text_view_scroll_to_mark(wd->GUI->txtview, wd->GUI->mark, 0.0, TRUE,
1.0, 0.0);
return G_SOURCE_REMOVE;
}
Output in a GtkTextview:
The textview displays messy strings with @
and i suppose it has something to do with not having a null ended string of characters or wrong size , my conversion from string to char, is the suspect.
Valid messa@ Valid messa@ Valid message : O@ Valid message : O@
The ouutput in shell:
Gtk-CRITICAL **: gtk_text_buffer_emit_insert: assertion 'g_utf8_validate (text, len, NULL)' failed
But i am expecting something like this :
Valid message : Ok...
Valid message : Ok...
Valid message : Ok...
Valid message : Ok...