On 20 April 2017 at 11:03, Rúben Rodrigues <ruben...@live.com.pt> 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
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
  • Doubt Rúben Rodrigues
    • Re: Doubt Emmanuele Bassi

Reply via email to