Qt程序在QPainter :: drawPixmap()上崩溃

时间:2017-12-19 17:36:38

标签: c++ qt qt4 qt5

我遇到问题,我的Qt程序在调用QPainter::drawPixmap()后崩溃了。我花了两天时间调试这个并决定我必须无意中滥用Qt的某些功能。

A working example of this problem can be found here

我的代码包含一个更新以下资产的QML文件:

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 = result.center;
    }
    update();
}

void Map::setLatitude(qreal latitude)
{
    this->latitude = latitude;
}

反过来又会重新生成一个新的Pixmap

MapTile updatePixmap(double scale, double longitude, double latitude)
{

    QPixmap myPixmap(800, 400);
    myPixmap.fill(Qt::transparent);
    QPainter painter(&myPixmap);
    painter.translate(400, 240);
    QPen pen;

    pen.setColor(Qt::white);
    pen.setWidth(1);
    painter.setPen(pen);
    QRectF boundaries(QPointF(-91.55 , 41.55) * scale,
                     QPointF(-91.45, 41.45) * scale);
    boundaries.translate(-longitude * scale, -latitude * scale);
    painter.drawRect(boundaries);
    painter.end();

    QGeoCoordinate center(latitude, longitude);
    return MapTile(myPixmap, center);
}

然后在适当的位置在屏幕上绘制这个新的像素图。重要的是要注意程序在崩溃之前运行几秒钟。

它在qdrawhelper_sse2.cpp第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);

}

这是坠机时刻的图像

enter image description here

1 个答案:

答案 0 :(得分:0)

这是Qt 5.9和5.10中的错误。请参阅here