Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Linux non Gui Application drawImage crash
QtWS25 Last Chance

Linux non Gui Application drawImage crash

Scheduled Pinned Locked Moved General and Desktop
14 Posts 5 Posters 10.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Franzk
    wrote on last edited by
    #3

    That does mean you cannot run your application without a running X session.

    "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

    http://www.catb.org/~esr/faqs/smart-questions.html

    1 Reply Last reply
    0
    • H Offline
      H Offline
      Henrik
      wrote on last edited by
      #4

      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.

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goetz
        wrote on last edited by
        #5

        "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 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).

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply
        0
        • H Offline
          H Offline
          Henrik
          wrote on last edited by
          #6

          I have a QApplication. Here is some sample code:

          svgexperiment.pro
          @QT += core
          QT += svg

          TARGET = svgexperiment
          CONFIG += console
          CONFIG -= app_bundle

          TEMPLATE = 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;
          }

          @

          1 Reply Last reply
          0
          • B Offline
            B Offline
            blex
            wrote on last edited by
            #7

            What do you exactly mean when you say "gui" or "non-gui"?

            My understanding is that "gui" uses QApplication, and "non-gui" uses QCoreApplication.


            Oleksiy Balabay

            1 Reply Last reply
            0
            • H Offline
              H Offline
              Henrik
              wrote on last edited by
              #8

              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.

              1 Reply Last reply
              0
              • H Offline
                H Offline
                Henrik
                wrote on last edited by
                #9

                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 ?

                1 Reply Last reply
                0
                • B Offline
                  B Offline
                  blex
                  wrote on last edited by
                  #10

                  [quote author="Henrik" date="1291188405"]Can someone tell me why this is done via QPixmap ?[/quote]

                  If the Qt code is clear in that place maybe the simplest way is to patch the Qt library? Sorry for stupid suggestion :)


                  Oleksiy Balabay

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    goetz
                    wrote on last edited by
                    #11

                    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.

                    http://www.catb.org/~esr/faqs/smart-questions.html

                    1 Reply Last reply
                    0
                    • E Offline
                      E Offline
                      erapid
                      wrote on last edited by
                      #12

                      @
                      #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.

                      1 Reply Last reply
                      0
                      • B Offline
                        B Offline
                        blex
                        wrote on last edited by
                        #13

                        Is X11 should be running or just libraries should be installed?


                        Oleksiy Balabay

                        1 Reply Last reply
                        0
                        • G Offline
                          G Offline
                          goetz
                          wrote on last edited by
                          #14

                          [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.

                          http://www.catb.org/~esr/faqs/smart-questions.html

                          1 Reply Last reply
                          0

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved