Re: Problem passing data to g_idle_add

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

 



Melvin Newman wrote:
> I am having a problem passing data into the g_idle_add() function. The
> exact
> line of code i am using is as follows:
> 
>    g_idle_add(update_server_version,(gpointer)data.data);
> 
> data is a structure, and data.data is a string of characters (char *). The
> data that I am passing into the g_idle_add() function is correct, however
> once the update_server_version() callback is called the data that is passed
> in is corrupted. Is there something wrong with what I am doing here?

Hi, you need to make sure that the data structure is allocated and valid
at the time that the idle callback is called. Perhaps you should do
something like:

	g_idle_add(update_server_version, g_strdup (data.data));

Which means the string has memory allocated for it. Then in the your
callback, you can call g_free (data) to make sure the memory is freed up
when you are done with it.

> gboolean update_server_version(GtkButton *button, gpointer data)
> {
>    /* Variables
>    ******************************************/
>    GtkWidget *server_version;
>    gchar *string_buffer;
>    /*****************************************/
> 
>    string_buffer = g_strdup_printf("V%s", (char *)data);
>    server_version=glade_xml_get_widget(xml,"label2");
>    gtk_label_set_text(server_version,string_buffer);
>    g_idle_remove_by_data(data);

Instead of using g_idle_remove_by_data() here, you should be able to
return FALSE in that function, for more information, see the
documentation for g_idle_add().

-- 
Regards,
Martyn
_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
http://mail.gnome.org/mailman/listinfo/gtk-list

[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux