gtk_signal_connect incompatible with C++?



Hi, I'm new to the list, and I'm pretty new to GTK, reasonably new to C++.
I saw a few posts in the archives about this but none seem to point
towards the kind of solution I'm looking for.  Anyway, the problem is I 
have a class called Panel, and one of its member functions is an 
adjustment callback. Inside one of the other Panel member functions, I 
connect the adjustment to the callback via this piece of code:

 gtk_signal_connect(GTK_OBJECT(KnobData[id]), 
         "value_changed", GTK_SIGNAL_FUNC(knobAdjustCallback), 
         pIds+id);

So KnobData[id] contains the pointer to the adjustment, knobAdjustCallback
is the callback, and pIds+id is a pointer to an int16 (short) which is the 
id for the particular knob associated with the adjustment.

The callback declaration is:

void Panel::knobAdjustCallback(GtkAdjustment *adj, int16 *pId)

Now the problem, which I discovered using gdb, is that there is a hidden
first parameter in Panel::knobAdjustCallback, namely the this pointer.
So when the callback is triggered, parameters come in out of alignment.
The this pointer gets overwritten with the adj pointer, and the adj
pointer gets overwritten with the pId pointer.  Meanwhile, the pId
pointer points to garbage, so I end up with segmentation fault.

If there isn't an easy way around this, am I better off convincing the
administrator to install GTK-- (which I hope *is* compatible with C++)?
Doing things like defining the callback outside the class, etc. isn't 
really an option (although it "fixes" the problem). If there's a patch
underway that addresses this problem, please let me know.

Thanks,
--Harvey

 



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