Re: Problem passing data to g_idle_add

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

 



Martyn:

Thank you very much for your reply. Yes shortly after posting, i found out that returning false was the right way to do things.

At this time things are working as I had designed, and intended... I am not sure why things started working, but they are working so I am not going to ask to many questions. Basically I just used a global variable to pass information into my update_server_version function. I simply cant figure out how to get the g_idle_add() function to pass in the argument without mangling the data.

Personally I do not like using global variables as I have been taught that they are inherently evil, but in this case (and also in the pthread_creat case i have used in other programs) I can not seem to find a way to pass the data into the thread being created without it somehow being mangled.

Any way, things are working for the time being, though it seems to be running bandaged code.

Sincerely
Melvin Newman

On 1/29/07, Martyn Russell <martyn@xxxxxxxxxxx> wrote:
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