g_locale_to_utf8问题
char *animaltype = get_animal_type(tagbuf);
g_locale_to_utf8(animaltype, -1, NULL, NULL, NULL);
printf("animaltype %sn",animaltype); //调试时显示animaltype 为中文“山羊”(正是我想要的内容,可是却无法在编辑框内显示?)
gtk_entry_set_text(GTK_ENTRY(etyType),animaltype);
为什么编辑框无法显示animaltype?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
2楼正解。另外,不要忘了释放test。
楼上正解,这个函数的第一个参数const gchar类型
g_locale_to_utf8 ()
gchar* g_locale_to_utf8 (const gchar *opsysstring,
gssize len,
gsize *bytes_read,
gsize *bytes_written,
GError **error);
Converts a string which is in the encoding used for strings by the C runtime (usually the same as that used by the operating system) in the current locale into a UTF-8 string.
opsysstring :
a string in the encoding of the current locale. On Windows this means the system codepage.
len :
the length of the string, or -1 if the string is nul-terminated[1].
bytes_read :
location to store the number of bytes in the input string that were successfully converted, or NULL. Even if the conversion was successful, this may be less than len if there were partial characters at the end of the input. If the error G_CONVERT_ERROR_ILLEGAL_SEQUENCE occurs, the value stored will the byte offset after the last valid input sequence.
bytes_written :
the number of bytes stored in the output buffer (not including the terminating nul).
error :
location to store the error occuring, or NULL to ignore errors. Any of the errors in GConvertError may occur.
Returns :
The converted string, or NULL on an error.
g_locale_to_utf8函数的返回值才是utf8格式的编码,你在打印的时候是正常的,是因为打印的仍然是当前语言环境下面的编码,不是utf8的编码。
改为:
char * test = g_locale_to_utf8(animaltype, -1, NULL, NULL, NULL);
gtk_entry_set_text(GTK_ENTRY(etyType),test);