开发者

QPainter JNI call crashes the application

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 righ开发者_JAVA技巧t 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 [developer.qt.nokia.com].

The whole thing runs inside a java based web container.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜