Re: Pango-WARNING **: Invalid UTF-8 string passed to pango_layout_set_text()



On Mon, May 14, 2007 at 04:41:26AM -0700, beginner.c wrote:

I'm doing the following and get the above error (of course with the funny
characters). What am I doing wrong?

Beside using sprintf() (instead of at least g_snprintf())
which is always wrong, you are not posting selfcontained,
i.e. compilable and runable, code that actually exhibits
your problem.

int a = 0;
char *x;
char Text[500];

sprintf (Text,"Blah %i",a);
x = Text;

gtk_label_set_text (GTK_LABEL(label1),x);

This works:

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

int
main(int argc, char *argv[])
{
    GtkWidget *window, *label;
    int a = 0;
    char *x;
    char text[500];

    gtk_init(&argc, &argv);

    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

    label = gtk_label_new(NULL);
    sprintf(text, "Blah %i", a);
    x = text;

    gtk_label_set_text(GTK_LABEL(label), x);
    gtk_container_add(GTK_CONTAINER(window), label);

    gtk_widget_show_all(window);
    gtk_main();

    return 0;
}
============================================

So you must do something differently.  I guess variable text
goes out of scope and the stack space is reused for
something else before gtk_label_set_text() is called in
the actual code, but who knows...

Yeti

--
http://gwyddion.net/



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