GTK:Invalid UTF8 string passed to pango_layout_set_text()问题(已解决)
- #include<gtk/gtk.h>
- #include <strings.h>
- #include<stdlib.h>
- #include<unistd.h>
- GtkWidget *window;
- GtkWidget *iptxt;
- GtkWidget *porttxt;
- GtkWidget *table;
- GtkWidget *sendbutton;
- GtkWidget *stopbutton;
- GtkWidget *iplabel;
- GtkWidget *portlabel;
- char title[]="Oracle Monitor Platform";
- char iptext[15],porttext[4];
- void destroy( GtkWidget *widget, gpointer data )
- {
- gtk_main_quit();//退出程序
- }
- void send_clicked(GtkWidget *widget,gpointer data)
- {
- strcpy(iptext,gtk_entry_get_text(GTK_ENTRY(iptxt)));//get ip to iptext
- strcpy(porttext,gtk_entry_get_text(GTK_ENTRY(porttxt)));//get port to porttext
- }
- void stop_clicked(GtkWidget *widget,gpointer data)
- {
- //system("/startoracle.sh start");
- //execl("/mytest.c",NULL);
- }
- void interface()//interface design
- {
- window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
- gtk_window_set_title((GtkWindow*)window,title);
- gtk_widget_set_usize(window,600,400);
- gtk_widget_set_uposition(window,200,150);
- table=gtk_table_new(
- 4,4,FALSE);
- iplabel=gtk_label_new("IP Address:");//label:add IP address
- iptxt=gtk_entry_new_with_max_length(15);//add ip txt
- portlabel=gtk_label_new("PORT:");//label:add PORT ID
- porttxt=gtk_entry_new_with_max_length(4);//add port txt
- sendbutton=gtk_button_new_with_label("SEND");//button:send message
- stopbutton=gtk_button_new_with_label("STOP");//button:stop send message
- gtk_container_add((GtkContainer*)window,table);//add container
- gtk_table_attach(GTK_TABLE(table),sendbutton,0,1,3,4,(GtkAttachOptions)(GTK_FILL),(GtkAttachOptions)(0),0,0);
- gtk_table_attach(GTK_TABLE(table),stopbutton,2,3,3,4,(GtkAttachOptions)(GTK_FILL),(GtkAttachOptions)(0),0,0);
- gtk_table_attach(GTK_TABLE(table),iplabel,0,1,0,1,(GtkAttachOptions)(GTK_FILL),(GtkAttachOptions)(0),0,0);
- gtk_table_attach(GTK_TABLE(table),portlabel,0,1,1,2,(GtkAttachOptions)(GTK_FILL),(GtkAttachOptions)(0),0,0);
- gtk_table_attach(GTK_TABLE(table),iptxt,2,3,0,1,(GtkAttachOptions)(GTK_FILL),(GtkAttachOptions)(0),0,0);
- gtk_table_attach(GTK_TABLE(table),porttxt,2,3,1,2,(GtkAttachOptions)(GTK_FILL),(GtkAttachOptions)(0),0,0);
- gtk_widget_show(window);
- gtk_widget_show(table);
- gtk_widget_show(iptxt);
- gtk_widget_show(porttxt);
- gtk_widget_show(sendbutton);
- gtk_widget_show(stopbutton);
- gtk_widget_show(iplabel);
- gtk_widget_show(portlabel);
- }
- void addsignal()//set signal
- {
- //当使用窗口管理器关闭窗口时,将调用 delete_event() 函数
- //本例中所传递的参数是 NULL
- gtk_signal_connect (GTK_OBJECT (window), "delete_event",gtk_main_quit, NULL);
- //把 "destroy" 事件和信号处理器联系起来
- //gtk_signal_connect (GTK_OBJECT (window), "destroy",GTK_SIGNAL_FUNC (destroy), NULL);
- //建立一个标签是"Hello World"的按钮
- //button = gtk_button_new_with_label ("Hello World");
- //当按钮被单击时,调用 gtk_widget_destroy(window)关闭窗口。
- //这里将引发 "destroy" 信号
- //gtk_signal_connect_object (GTK_OBJECT (sendbutton), "clicked",GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT (window));
- //当按钮被单击时,即接收到"clicked"信号,将调用destroy()函数
- //gtk_signal_connect (GTK_OBJECT (sendbutton), "clicked",GTK_SIGNAL_FUNC (destroy), NULL);
- //当按钮被单击时,即接收到"clicked"信号,将调用 hello()函数
- gtk_signal_connect (GTK_OBJECT (stopbutton), "clicked",GTK_SIGNAL_FUNC (stop_clicked), NULL);
- }
- int main(int argc,char *argv[])
- {
- //gtk_set_locale();
- gtk_init(&argc,&argv);//gtk 初始化
- interface();
- addsignal();
- gtk_main();
- return 0;
- }
复制代码我运行上述程序时出现:
** (hello:843): WARNING **: Invalid UTF8 string passed to pango_layout_set_text()
** (hello:843): WARNING **: Invalid UTF8 string passed to pango_layout_set_text()
的警告,应该怎么解决阿?请高手指教!
[ 本帖最后由 pc521 于 2010-1-28 19:20 编辑 ]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用g_locale_to_utf8()函数。
使用方法:
g_locale_to_utf8(“确定”,-1,0,0,0)
可以定义一个函数,以后调用这个函数比较方便。
char *_(char *c)
{
return(g_locale_to_utf8(c,-1,0,0,0));
}
如果需要调用就用 _("确定")就可以了。
比如设置标题:
gtk_window_set_title (GTK_WINDOW (window), _("你好!"))