Linux non Gui Application drawImage crash
-
The problem is i want an application which does not need a X server. And think it has nothing to do with image processing, because there is no problem in drawing a QImage on QImages or QPrinters. Only when i try to draw a QImage on a QSvgGenerator it crashes.
-
"QSvgGenerator":http://doc.qt.nokia.com/4.7/qsvggenerator.html inherits from "QPaintDevice":http://doc.qt.nokia.com/4.7/qpaintdevice.html.
bq. 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 createdBut 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
@QT += core
QT += svgTARGET = svgexperiment
CONFIG += console
CONFIG -= app_bundleTEMPLATE = app
SOURCES += main.cpp@
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
QApplication a(argc, argv, false);// create an image
QImage img(300, 200, QImage::Format_ARGB32_Premultiplied);// draw some stuff on the image
QPainter p(&img);
p.setPen(Qt::blue);
p.setBrush(Qt::green);
p.drawEllipse(img.rect());
p.end();
img.save("/home/henrik/img_1.png");// copy img and overwrite the copies content
QImage sndImg(img);
sndImg.fill(QColor(Qt::red).rgba());
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.setSize(QSize(300,200));
generator.setResolution(300);
generator.setViewBox(QRect(QPoint(0,0), generator.size()));// draw on the generator
p.begin(&generator);
p.fillRect(0,0, 150,100, Qt::yellow);
p.drawImage(0,0, img); // this line crashes if it's a non gui application
p.end();return 0;
}@
-
bq. 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&, QFlagsQt::ImageConversionFlag) ()
from /usr/lib/libQtGui.so.4
#3 0xb770fd0c in QPixmap::fromImage(QImage const&, QFlagsQt::ImageConversionFlag) () from /usr/lib/libQtGui.so.4
#4 0xb7776d5e in QPaintEngine::drawImage(QRectF const&, QImage const&, QRectF const&, QFlagsQt::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, QFlagsQt::ImageConversionFlag) ()
#7 0x08049575 in main ()
@@
int QX11Info::appDepth(int screen)
{
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.
-
[quote author="blex" date="1291440121"]Is X11 should be running or just libraries should be installed?[/quote]
X11 must be running and you must have set your DISPLAY environment variable. If you unset DISPLAY the X11 GUI cannot be initialized and the program fails to start.