[Qgis-developer] [Qgis-user] Segfault when using QgsComposition::exportAsPDF with QGIS 2.4 and python
Martin Dobias
wonder.sk at gmail.com
Wed Aug 20 02:16:27 PDT 2014
Hi
>> 2014-08-19 22:48 GMT+02:00 Nyall Dawson <nyall.dawson at gmail.com>:
>>> >
>>>
>>> Does it make any difference if you change:
>>> c = QgsComposition(QgsMapSettings())
>>>
>>> To:
>>> ms=QgsMapSettings()
>>> c=QgsComposition(ms)
>>>
>>> ?
>
> Martin/other python experts,
>
> What's the best way to fix this? Is /Transfer/ appropriate, given that the
> c++ code would never delete this object? Or is there an alternative sip flag
> which is more appropriate for this?
I think this is really API problem rather than Python-specific issue.
The QgsComposition is designed in a way that it always had
QgsMapRenderer from map canvas accessible (now changed to
QgsMapSettings). Worst of all, it is supposed to be the same instance
as used by map canvas - so it keeps just reference/pointer to
QgsMapSettings/QgsMapRenderer. The QgsComposition should be fixed so
that it does not require QgsMapSettings/QgsMapRenderer - after all, it
does not make much sense, there may be several composer map items with
different configuration. Each QgsComposerMap should have its own
QgsMapSettings instance.
The root of the problem here is that the QgsMapSettings() will create
an instance and then destroy it - while QgsComposition just keeps
blindly using dead reference. /Transfer/ or other annotations will
IMHO not solve the problem. I would consider is as a known issue and
live with it until API is not fixed.
Btw. using "c = QgsComposition( QgsMapRenderer() )" is also wrong
because of the same reasons. If it worked, it was just luck :-)
Regards
Martin
More information about the Qgis-developer
mailing list