Invalid UTF-8 string passed to pango_layout_set_text()



Hi list,
I'm learning GTK+ using "Foundations of GTK+ Development" by Andrew Krause and today I did the exercise2-1(chapter2) which should meet the demand as follows:
when press the key,the label's text and window's title can interchange.
However,I got the warning:"Invalid UTF-8 string passed to pango_layout_set_text()".
The label's text will be messy character when I first press SHIFT and both become messy when I press key at the second time.
The code is as follows and please note my comments:
#include<gtk/gtk.h>
#include<gdk/gdkkeysyms.h>
static gboolean changeTitle(GtkWidget* window,
            GdkEventKey* keyEvent,
    GtkLabel *label)
{
const gchar *textLabel=gtk_label_get_text(GTK_LABEL(label));
const gchar         *textWindow=gtk_window_get_title(GTK_WINDOW(window));

if(keyEvent->keyval==GDK_Shift_L)
{
                //surprise,if I skip(via "//") one of the two lines, another
                //will work fine.....
       gtk_window_set_title(GTK_WINDOW(window),textLabel);
       gtk_label_set_text(GTK_LABEL(label),textWindow);
}
return FALSE;
}

int main(int argc,char *argv[])
{
GtkWidget *main_window;
GtkWidget *selec_label;

gtk_init(&argc,&argv);

main_window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(main_window),"Qiuxyu");
gtk_widget_set_size_request(GTK_WIDGET(main_window),200,100);
gtk_window_set_resizable(GTK_WINDOW(main_window),FALSE);
g_signal_connect(G_OBJECT(main_window),"destroy",G_CALLBACK
                 (gtk_main_quit),NULL);

selec_label=gtk_label_new("Randy");
gtk_label_set_selectable(GTK_LABEL(selec_label),TRUE);

g_signal_connect(G_OBJECT(main_window),"key_press_event",
         G_CALLBACK(changeTitle),(gpointer)selec_label);

gtk_container_add(GTK_CONTAINER(main_window),selec_label);

gtk_widget_show_all(main_window);

gtk_main();
return 0;
}

Thanks for any clue!

Best regards,
Randy

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]