Hi Peter,
I've been using ChartDirector in a PyQt desktop application by wrapping
QChartViewer.cpp with sip and generating a PyQt widget from it. This mostly works
without any hassle, except for a few QChartViewer functions that take a ChartDirector
object as an argument (setChart and the axis syncing methods). I've looked at the
implementation of pychartdir.py and chartdir.h, and it seems that the only link between
the python representations of chartdir objects and the underlying chartdir objects is a
string containing the address of the relevant internal pointer. I can parse out this
address using a regular expression and pass it into my PyQt wrapper as a long and then
reinterpret_cast it into the pointer. For example, here is the wrapper implementation for
setChart:
void setChart(long address);
%MethodCode
BaseChart* chart = new BaseChart();
chart->init(reinterpret_cast<BaseChartInternal *>(a0));
sipCpp->setChart(chart);
%End
This approach works - however, it is a bit fragile (and I believe leaks a BaseChart
object). Python has a special type of object which can wrap a C pointer (CObject up to
py2.6 and Capsules in 2.7 and beyond). Do you think it would be possible to change the
python bindings to add a special attribute to each ChartDir python object that contains
one of these objects? That way I could pull out the pointer directly from the python
ChartDir object with out having to parse the address from the "this" attribute.
Incidentally, what license is the QChartViewer code under? Since I have a license to
chartdir can I freely use the QChartViewer code in my application? Thanks.
Regards,
Naveen Michaud-Agrawal |