当我尝试运行以下代码片段时,我不断收到此错误和奇怪的乱码:
错误是:
(foo:11333): Pango-WARNING **: 传递给 pango_layout_set_text() 的 UTF-8 字符串无效
结构定义:
typedef struct chat_info ChatInfo;
struct chat_info {
GtkWidget *text_line1;
GtkWidget *text_line2;
GtkWidget *text_line3;
GtkWidget *entry;
};
这段代码使第三个标签上出现了奇怪的乱码(第二个标签为空)
static void send_message(GtkWidget *window, gpointer data){
GuiInfo *g = (GuiInfo *) data;
ChatInfo *c = g->chat;
const gchar *message = gtk_entry_get_text(GTK_ENTRY(c->entry));
const gchar *oldtext1 = gtk_label_get_text( (GtkLabel *) c->text_line1);
const gchar *oldtext2 = gtk_label_get_text( (GtkLabel *) c->text_line2);
gtk_label_set_text( (GtkLabel *) c->text_line1, message);
gtk_label_set_text( (GtkLabel *) c->text_line2, oldtext1);
gtk_label_set_text( (GtkLabel *) c->text_line3, oldtext2);
}
我查看了错误,我猜这可能是由于我应该给出一个 gchar 字符串时给出一个指针地址之类的东西?一切看起来都不错。