Linux non Gui Application drawImage crash
When I make a drawImage in a non gui linux application on a QPainter on QSvgGenerator I get “Segmentation fault”. Is this the normal behaviour ? Drawing of QPainterPaths or QRects works fine.
13 replies
QSvgGenerator [doc.qt.nokia.com] inherits from QPaintDevice [doc.qt.nokia.com].
From the QPaintDevice docs:
Warning: Qt requires that a QApplication object exists before any paint devices can be created. Paint devices access window system resources, and these resources are not initialized before an application object is created
But it seems as if you have a graphics system initialized already. Could you give us a simple working example that demonstrates the bug (C++ sources for a main.cpp and a .pro).
I have a QApplication. Here is some sample code:
svgexperiment.pro
main.cpp
- #include <QtCore>
- #include <QtGui>
- #include <QtSvg>
- int main(int argc, char *argv[])
- {
- // initialize application
- // if I set the gui parameter to true it works without problems
- // create an image
- // draw some stuff on the image
- p.drawEllipse(img.rect());
- p.end();
- img.save("/home/henrik/img_1.png");
- // copy img and overwrite the copies content
- p.begin(&img);
- p.drawImage(0,0, sndImg); // write image on image to show that this works
- p.end();
- // save this image for control reasons
- img.save("/home/henrik/img_2.png");
- // create a svg generator
- QSvgGenerator generator;
- generator.setFileName("/home/henrik/generated.svg");
- generator.setResolution(300);
- // draw on the generator
- p.begin(&generator);
- p.drawImage(0,0, img); // this line crashes if it's a non gui application
- p.end();
- return 0;
- }
QApplication::QApplication ( int & argc, char ** argv, bool GUIenabled )
Constructs an application object with argc command line arguments in argv. If GUIenabled is true, a GUI application is constructed, otherwise a non-GUI (console) application is created.
I mean this third QApplication parameter.
I found out that drawImage in QSvgGenerators PaintEngine want’s to convert the QImage to a QPixmap and this doesn’t work if the application isn’t connected to a X server.
I don’t understand why this is neccessary, image data is just saved as PNG data int the svg file and this is normally done with QImage and not QPixmap.
Can someone tell me why this is done via QPixmap ?
For some reasons there might be some transformations on the image (e.g. to scale it to the bounding rect or some transformation matrix). This is done using pixmaps. Even calling the paintEngine() pointer of QSvgGenerator directly does not help (this does not use a QPixmap). I don’t know why this is not called correctly. Maybe you should open a bug at http://bugreports.qt.nokia.com.
- #0 0xb76d342d in QX11Info::appDepth(int) () from /usr/lib/libQtGui.so.4
- #1 0xb76d35e4 in QX11Info::depth() const () from /usr/lib/libQtGui.so.4
- #2 0xb7725c70 in QX11PixmapData::fromImage(QImage const&, QFlags<Qt::ImageConversionFlag>) ()
- from /usr/lib/libQtGui.so.4
- #3 0xb770fd0c in QPixmap::fromImage(QImage const&, QFlags<Qt::ImageConversionFlag>) () from /usr/lib/libQtGui.so.4
- #4 0xb7776d5e in QPaintEngine::drawImage(QRectF const&, QImage const&, QRectF const&, QFlags<Qt::ImageConversionFlag>) () from /usr/lib/libQtGui.so.4
- #5 0xb7790e3b in QPainter::drawImage(QPointF const&, QImage const&) () from /usr/lib/libQtGui.so.4
- #6 0x080499e6 in QPainter::drawImage(int, int, QImage const&, int, int, int, int, QFlags<Qt::ImageConversionFlag>) ()
- #7 0x08049575 in main ()
- {
- return X11 ? X11->screens[screen == -1 ? X11->defaultScreen : screen].depth : 32;
- }
:( Have no time to dig deeper right now, but I have to say that I got similar situation when trying to convert html to pdf by Qt printer. It can be done only in QApplication with X11 or qws access.
You must log in to post a reply. Not a member yet? Register here!



