Important: Please read the Qt Code of Conduct -

Qt crash in QRasterPaintEngine::alphaPenBlt() while painting label text

  • In our embedded Qt application, Qt is crashing with a segmentation fault in function QRasterPaintEngine::alphaPenBlt() while it's painting a label text and it generates core file too. Always I get the following call stack from the core files.

    #0 0x4074e234 in QRasterPaintEngine::alphaPenBlt(void const*, int, int, int, int, int, int) ()
    from /home/local/.../armv6jel-wrlinux_3_0/arm-wrs-linux-gnueabi/sysroot/lib/
    #1 0x4088eeb0 in QFontEngineQPF::draw(QPaintEngine*, float, float, QTextItemInt const&) ()
    from /home/local/.../armv6jel-wrlinux_3_0/arm-wrs-linux-gnueabi/sysroot/lib/
    #2 0x4088eeb0 in QFontEngineQPF::draw(QPaintEngine*, float, float, QTextItemInt const&) ()
    from /home/local/.../armv6jel-wrlinux_3_0/arm-wrs-linux-gnueabi/sysroot/lib/
    Backtrace stopped: previous frame identical to this frame (corrupt stack?)

    After doing a quick Google search I found this reported Qt-Bug : which has not been attended yet. But applying the suggested fix as per this bug report, ie changing "glyphPos > glyphDataSize" to "glyphPos >= glyphDataSize" in qt-everywhere-opensource-src-4.7.4/src/gui/text/qfontengine_qpf.cpp findGlyph() function I'm not observing the crash.

    I'm not aware of Qt source code. Please let me know, if I should go ahead with the fix proposed by the reporter.

  • Lifetime Qt Champion


    If it works correctly and doesn't have other side effects, then go on.

  • Thank you SGaist.

    Even I was thinking of go-ahead with the code changes, but worried that, even after more than a year, no one from Qt support actually attended the bug raised here Neither they have verified the bug nor made any progress on it, not even a comment !!!

    Can you please tell me, Is it a expected norm of Qt bug reporting system ?

  • Lifetime Qt Champion

    No it's not, but you also have to understand that the Qt Company only has so much man power so they have to prioritize bugs. I know this means that sometimes certain bugs will take longer to get fixed. Note that since the project is OpenSource, you can also contribute fixes that will benefit everyone of the Qt Community.

    You should also be aware that Qt 4.7.4 is quite outdated. The latest release of the Qt 4 series is 4.8.7.

    Last thing to know is that 4.8.7 is the last release of the Qt 4 series unless there's a need for a security fix.

  • I'm also having a crash with similar stack trace in Qt 5.6.3.
    In a QGraphicsView, if I try to paint a QGraphicsItem with a text (i.e. painter->drawText(...) inside the paint method) and zoom out the view a lot, it crashes on Windows (32 bits and 64 bits, MSVC2015, Windows 7-10). On Mac OS (64bits) it works ok. It seems that Qt may have trouble drawing extremely small texts (with the size of 1 pixel or less) on Windows. The error message is:

    Error: QWinFontEngine: unable to query transformed glyph metrics (GetGlyphOutline() failed, error 1003)... (Cannot complete this function.)

    My workaround was to always test the level of detail before draw any text:

    void Gate::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
        if(option->levelOfDetailFromTransform(painter->worldTransform()) < 0.005) 

    Stack trace:

    1 QRasterPaintEngine::alphaPenBlt qpaintengine_raster.cpp 2519 0x62bdd032
    2 QRasterPaintEngine::drawCachedGlyphs qpaintengine_raster.cpp 2829 0x62bdccca
    3 QRasterPaintEngine::drawTextItem qpaintengine_raster.cpp 3036 0x62bdaea3
    4 QPainterPrivate::drawTextItem qpainter.cpp 6505 0x62bfc30a
    5 QTextLine::draw qtextlayout.cpp 2597 0x62a84452
    6 qt_format_text qpainter.cpp 7633 0x62bfe3cc
    7 QPainter::drawText qpainter.cpp 6019 0x62bf7fa8
    8 Gate::paint panorama.cpp 46 0xc04718

  • Lifetime Qt Champion


    What version of Qt ?
    What version of Windows ?
    What compiler ?

  • @SGaist Sorry. I added more details in my first post. I also added my workaround and what I think the problem is.

  • Lifetime Qt Champion

    Thanks for sharing your workaround !

    Did you try to take a look at the bug report system to see if something related already exists ?

  • I found some similar, but i'm not sure if they are the same thing since their Qt versions are not the same and the stack trace differs a little.

    I tested today with Win64 and it also crashes.

  • I found that this application also has the same issue (same error message when doing the same thing):

Log in to reply