首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >Qt程序在QPainter::drawPixmap()上崩溃

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

Stack Overflow用户
提问于 2017-12-20 01:36:38
回答 1查看 704关注 0票数 1

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

A working example of this problem can be found here

我的代码由一个更新以下属性的QML文件组成:

代码语言:javascript
代码运行次数:0
运行
复制
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

代码语言:javascript
代码运行次数:0
运行
复制
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行出现段故障错误。

代码语言:javascript
代码运行次数:0
运行
复制
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);

}

这是坠机时刻的图像

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-03-22 22:45:47

这是Qt 5.9和5.10中的一个错误。参见here

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47892398

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档