>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)); > As you can see here, these gchar* are owned by the label/window, and upon you setting the window title, the textWindow point to something might already been freed, so cause these strange problem. You need something like gchar *textWindow= g_strdup(gtk_window_get_title(GTK_WINDOW(window))); to store the tmp string data, and free it after you done with gtk_label_set_text in your code below >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; >} >Thanks for any clue! >Best regards, >Randy Raymond _______________________________________________ gtk-list mailing list gtk-list@xxxxxxxxx http://mail.gnome.org/mailman/listinfo/gtk-list