Re: beginner needs help with "casting" with gtk



On Sun, Jun 21, 2009 at 02:13:52PM +0200, Julien Martin wrote:
> *static void hello(GtkWidget *widget, gpointer data) {
>     gchar * _data = (gchar *) data;
>     g_print(_data);
>     g_print("\n");
> }*
> 
> wich I call as follows:
> *
> g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(hello), "hello
> toto");*
> 
> I get the following warning each time I compile:
> 
> *warning: the format is not a litteral string and no format argument*
> 
> Can anyone please help?
> I need to "cast" the data variable to gchar *. What am I doing wrong?

The problem is not in the typecasting.  The problem is that if you do
(directly or indirectly)

  g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(hello), "%s");

your program will crash.  Print the message as

  g_print("%s\n", data);

Yeti



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