I realize specific questions like this aren't great, but I've spent several days trying to puzzle this out. Hopefully someone here can help.
This python code using PyQt4 causes a segmentation fault:
data = """<?xml version="1.0" ?>
<svg height="1000" width="2000">
<text>blah</text>
</svg>"""
svg = QSvgRenderer(QByteArray(data))
qim = QImage(int(width), int(height), QImage.Format_ARGB32)
painter = QPainter()
painter.begin(qim)
svg.render(painter)
painter.end()
qim.save('test2.png')
The line that causes the fault is svg.render(painter)
.
The fault points at libQtGui.so
(so something in QPainter
or QImage
).
svg.isValid()
returns True
, and qim.isNull()
returns False
.
With only a minor change to make that run (defining width and height), it works for me. Note that I don't see any text but if I swap out data to something I know is valid it works perfectly. Here's my full code:
#!/usr/bin/env python
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from PyQt4.QtSvg import *
import sys
if __name__ == '__main__':
app = QApplication(sys.argv)
data = """... (my valid svg) ..."""
svg = QSvgRenderer(QByteArray(data))
qim = QImage(int(2000), int(1000), QImage.Format_ARGB32)
painter = QPainter()
painter.begin(qim)
svg.render(painter)
painter.end()
print "null:", qim.isNull()
qim.save('test2.png')