Doubt

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Doubt

Rúben Rodrigues
Hi guys,

i have a problem with callback functions. I have a struct in parameter but always give null values. Here is an example:


struct pxToggleData{
    LineChartSeries *series;
    LineChart *chart;
    GtkWidget *canvas;
};

xTempToggle.canvas = canvas;
xTempToggle.chart = chart;

xTempToggle.series = pxLogView_TempSensors[iProbe].series;

g_signal_connect((GObject *)pxLogView_TempSensors[iProbe].cButton, "toggled", (GCallback)series_toggled, &xTempToggle);

Someone could help me? Why it give always xTempToggle null in series_toggled callback function?

--
Rúben Rodrigues
AUTOFRAN, Lda
www.autofran.net<http://www.autofran.net>

[https://ipmcdn.avast.com/images/icons/icon-envelope-tick-round-orange-animated-no-repeat-v1.gif]<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient>      Sem vírus. www.avast.com<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient>
_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: Doubt

Emmanuele Bassi
On 20 April 2017 at 11:03, Rúben Rodrigues <[hidden email]> wrote:

> Hi guys,
>
> i have a problem with callback functions. I have a struct in parameter but always give null values. Here is an example:
>
>
> struct pxToggleData{
>     LineChartSeries *series;
>     LineChart *chart;
>     GtkWidget *canvas;
> };
>
> xTempToggle.canvas = canvas;
> xTempToggle.chart = chart;
>
> xTempToggle.series = pxLogView_TempSensors[iProbe].series;
>
> g_signal_connect((GObject *)pxLogView_TempSensors[iProbe].cButton, "toggled", (GCallback)series_toggled, &xTempToggle);
>
> Someone could help me? Why it give always xTempToggle null in series_toggled callback function?

This is kind of a basic C question.

You're passing a pointer to data placed on the stack. If xTempToggle
goes out of scope after g_signal_connect() is called, then the data
points to random garbage.

You need to either put the xTempToggle data structure in a larger
scope (e.g. global) or you need to put it on the heap, and manage the
memory allocation yourself.

Ciao,
 Emmanuele.

--
https://www.bassi.io
[@] ebassi [@gmail.com]
_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list