Re: Doubt
- From: Emmanuele Bassi <ebassi gmail com>
- To: Rúben Rodrigues <ruben_gr live com pt>
- Cc: "gtk-app-devel-list gnome org" <gtk-app-devel-list gnome org>
- Subject: Re: Doubt
- Date: Fri, 21 Apr 2017 11:29:57 +0100
On 20 April 2017 at 11:03, Rúben Rodrigues <ruben_gr 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]
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]