Important: Please read the Qt Code of Conduct -

Program crashes on QPainter::drawPixmap()

  • I am having problem where my Qt program crashes after calling QPainter::drawPixmap(). I have spent 2 days debugging this and have decided that I must be unintentionally abusing some feature of Qt.

    A working example of this problem can be found here.

    My code consists of a QML file that updates the following properteries:

    Q_PROPERTY(qreal longitude READ getLongitude WRITE setLongitude NOTIFY latitudeChanged)
    Q_PROPERTY(qreal latitude READ getLatitude WRITE setLatitude NOTIFY latitudeChanged)
    void Map::setLongitude(qreal longitude)
        double diff = (this->longitude - this->pixmapCenter.longitude()) * scale;
        this->longitude = longitude;
        if (qFabs(diff) > 50)
            MapTile result = updatePixmap(scale, longitude, latitude);
            pixmap = result.pixmap;
            pixmapCenter =;
    void Map::setLatitude(qreal latitude)
        this->latitude = latitude;

    That in turn regenerates a new Pixmap

    MapTile updatePixmap(double scale, double longitude, double latitude)
        QPixmap myPixmap(800, 400);
        QPainter painter(&myPixmap);
        painter.translate(400, 240);
        QPen pen;
        QRectF boundaries(QPointF(-91.55 , 41.55) * scale,
                         QPointF(-91.45, 41.45) * scale);
        boundaries.translate(-longitude * scale, -latitude * scale);
        QGeoCoordinate center(latitude, longitude);
        return MapTile(myPixmap, center);

    This new pixmap is then drawn on the screen at the appropriate location. It is important to note that the program runs fine for a few seconds before it crashes.

    It crashes with a segfault error in qdrawhelper_sse2.cpp line 587.

    void Map::paint(QPainter *painter)
        painter->translate(boundingRect().width()/2, boundingRect().height()/2);
        painter->scale(1, -1);
        painter->translate((pixmapCenter.longitude() - longitude) * scale,
                           (pixmapCenter.latitude() - latitude) * scale);
        QPoint corner(-pixmap.width()/2, -pixmap.height()/2);
        painter->drawPixmap(corner, this->pixmap);

    Here is an image of the moment of the crash

    enter image description here

    enter image description here

  • It turns out this is a bug. See here.

  • What's in line 42 of Map::paint?

  • Moderators

    @VRonin said in Qt program crashes on QPainter::drawPixmap():

    What's in line 42 of Map::paint?

    You debug window says "Source file is more recent than executable"
    Can you try a full rebuild (clean & build)

  • @raven-worx I saw that earlier and already tried the a clean/rebuild. I even deleted the entire project and cloned the repo again.

    I just noticed that this does not happen in release configuration. I have submitted a Qt bug report.

    My environment is MinGW 5.3.0 on Windows 7 (or 10)

  • It turns out this is a bug. See here.

Log in to reply