Web blog of yydzero
姚延栋(Yandong Yao)的博客
归档
« 十一月 2009
星期日星期一星期二星期三星期四星期五星期六
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
     
       
今天
Click me to subscribe
Search In My Blog

链接
 

今日点击: 81

Locations of visitors to this page
« The encoding of... | Main | Why python minutes »
星期三 一月 18, 2006
The encoding returned from gtk widget is UTF-8 commonly
Gtk+ provide several widget to let user input characters, such as GtkEntry, gtk multiline widget, and then you can using some method such gtk_entry_get_text() got what user input. But question is: what is the encoding of returned text on different locale?

The answer is that the encoding is utf8 no matter on which locale user input it.

#include <gtk/gtk.h>
#include <stdio.h>

void
cb_activate (GtkEntry *entry, gpointer user_data)
{
    const gchar *text;

    text = gtk_entry_get_text (GTK_ENTRY(entry));

    if (text != NULL)
        printf ("The text returned from entry: %s\n", text);
    else
        printf ("The text returned from entry: NULL\n");
}

int
main (int argc, char **argv)
{
    GtkWidget *window;
    GtkWidget *entry;

    gtk_init (&argc, &argv);

    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title (GTK_WINDOW (window), "Test the encoding of text input by user");
    gtk_window_resize (GTK_WINDOW (window), 300, 100);
    g_signal_connect (window, "delete-event", G_CALLBACK (gtk_main_quit), NULL);
    g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);

    entry = gtk_entry_new ();
    g_signal_connect (entry, "activate", G_CALLBACK (cb_activate), NULL);
    gtk_container_add (GTK_CONTAINER (window), entry);

    gtk_widget_show_all (window);
    
    gtk_main ();

    return 0;
}
Posted at 03:30上午 一月 18, 2006 by Yaodong Zero Yao in gnome  |  评论[0]

评论:

发表一条评论:
  • HTML语法: 禁用