簡體   English   中英

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

[英]Qt program crashes on QPainter::drawPixmap()

我在調用QPainter::drawPixmap()之后Qt程序崩潰的問題。 我花了2天的時間進行調試,並決定必須無意中濫用Qt的某些功能。

有關此問題的有效示例,請參見此處

我的代碼包含一個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中因segfault錯誤而崩潰。

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);

}

這是墜機時刻的圖像

在此處輸入圖片說明

這是Qt 5.9和5.10中的錯誤。 這里

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM