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. QPainter JNI call crashes the application
Forum Updated to NodeBB v4.3 + New Features

QPainter JNI call crashes the application

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 3.8k Views 1 Watching
  • 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.
  • K Offline
    K Offline
    karthiksrini
    wrote on last edited by
    #1

    Hi,

    What I am trying to do -
    Make a JNI call to a shared library written in Qt. On the C++ side I am using QPainter and QSvgRender to manipulate an svg image and return a simple QImage.

    @ QImage im;
    QPainter painter;
    if("image/svg+xml" == mimeType) {
    QSvgRenderer svgrenderer(ar);
    im = QImage(static_cast<int> (svgrenderer.defaultSize().width()),
    static_cast<int> (svgrenderer.defaultSize().height()),
    QImage::Format_ARGB32);
    im = im.scaled(QSize(50,50), Qt::KeepAspectRatio);
    im.fill(0);
    painter.begin(&im);
    svgrenderer.render(&painter); //Crashes here
    }@

    What is the issue -

    The code crashes while calling render as shown. And it crashes only for certain SVG images.

    If I run the code within a stand alone Qt Application, it works fine.
    I hadn't created a QApplication instance within my shared lib as against a stand alone Qt App.
    So I decided to create one this way-

    From Java Main Thread - Spawn another thread which makes a JNI call to create a QApplication. Runs exec().

    From Java Main Thread continue to make other JNI calls after the QApplication is initialized.

    This still doesn't work. Any advise on what I may be doing wrong and what is the right way to do what I am trying to do?
    I have searched the forum and the web for solutions but nothing has helped. The only thread that came close to what I need is - "http://developer.qt.nokia.com/forums/viewthread/2283":http://developer.qt.nokia.com/forums/viewthread/2283.

    The whole thing runs inside a java based web container.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dangelog
      wrote on last edited by
      #2

      Apart from some polishing (you're not calling painter.end(), those static_cast are not needed at all, line 8 is absolutely nonsense (you're scaling an unitializated image then you fill it, so why don't you create an image of the right size from the beginning?)), the snippet seems ok, so the problem may be in any other part of the program. Can you write a small, self-contained, compilable example that crashes? (Eventually, by providing a SVG that makes it crash...)

      Software Engineer
      KDAB (UK) Ltd., a KDAB Group company

      1 Reply Last reply
      0
      • K Offline
        K Offline
        karthiksrini
        wrote on last edited by
        #3

        [quote author="peppe" date="1292837685"]Apart from some polishing (you're not calling painter.end(), those static_cast are not needed at all, line 8 is absolutely nonsense (you're scaling an unitializated image then you fill it, so why don't you create an image of the right size from the beginning?)), the snippet seems ok, so the problem may be in any other part of the program. Can you write a small, self-contained, compilable example that crashes? (Eventually, by providing a SVG that makes it crash...)[/quote]

        Thanks peppe for your thoughts. I understand what you've explained.

        1. I am calling painter.end() which is not shown in the code 'snippet' I've posted.
        2. Regarding line 8, I understand what you mean. But it works for me for images that don't crash the app. I need the svg to be scaled to 50x50 while keeping the aspect ratio. I do get the images scaled to 50x50. BUt like you said I could probably create an image of the right size from the beginning.
        3. I will try to write a compilable and attach it for you and others to see. Like I said this is happening as a part of a JNI call.

        I was hoping someone would give me some advice on how to use gui realted classes inside a shared library in a proper way and to be able to make calls from java via JNI.

        1 Reply Last reply
        0
        • K Offline
          K Offline
          karthiksrini
          wrote on last edited by
          #4

          Kind of solved the crashing issue. Seemed to be a bug in Java 1.5 that I was using http://bugs.sun.com/view_bug.do?bug_id=5102720

          I have fixed it for now by changing qt to make up for the stack realignment issue by adding these flags for qmake- QMAKE_CFLAGS += "-mstackrealign" QMAKE_CXXFLAGS += "-mstackrealign"

          The problem was mainly on windows

          1 Reply Last reply
          0
          • X Offline
            X Offline
            xffighting
            wrote on last edited by
            #5

            I used it , but when I compile it, there is error:

            cc1plus: error: unrecognized command line option ?-mstackrealign?

            I was use qpainter in jni on linux.

            Please help me !!

            [quote author="karthiksrini" date="1294042458"]Kind of solved the crashing issue. Seemed to be a bug in Java 1.5 that I was using http://bugs.sun.com/view_bug.do?bug_id=5102720

            I have fixed it for now by changing qt to make up for the stack realignment issue by adding these flags for qmake- QMAKE_CFLAGS += "-mstackrealign" QMAKE_CXXFLAGS += "-mstackrealign"

            The problem was mainly on windows[/quote]

            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