qtQuick源代码中的loadImage函数

时间:2017-10-17 15:58:16

标签: c++ qt canvas qml qtquick2

在qtQuick Source中。函数loadImage中有一行代码:

QQuickPixmap* pix = new QQuickPixmap();

如果我在画布上尽可能多地调用此函数。操作系统为此应用程序分配的内存将被填充,这将导致图片失败。我想询问是否有任何内容。这个源代码的问题?

void QQuickCanvasItem::loadImage(const QUrl& url)
{

    Q_D(QQuickCanvasItem);
    QUrl fullPathUrl = d->baseUrl.resolved(url);
    if (!d->pixmaps.contains(fullPathUrl)) {
        QQuickPixmap* pix = new QQuickPixmap();
        QQmlRefPointer<QQuickCanvasPixmap> canvasPix;
        canvasPix.adopt(new QQuickCanvasPixmap(pix));
        d->pixmaps.insert(fullPathUrl, canvasPix);

        pix->load(qmlEngine(this)
                , fullPathUrl
                , QQuickPixmap::Cache | QQuickPixmap::Asynchronous);
        if (pix->isLoading())
            pix->connectFinished(this, SIGNAL(imageLoaded()));
    }
}

1 个答案:

答案 0 :(得分:-3)

void QQuickCanvasItem::loadImage(const QUrl& url)
{

    Q_D(QQuickCanvasItem);
    QUrl fullPathUrl = d->baseUrl.resolved(url);
    if (!d->pixmaps.contains(fullPathUrl)) {
        QQuickPixmap* pix = new QQuickPixmap();
        QQmlRefPointer<QQuickCanvasPixmap> canvasPix;
        canvasPix.adopt(new QQuickCanvasPixmap(pix));
        d->pixmaps.insert(fullPathUrl, canvasPix);

        pix->load(qmlEngine(this)
                , fullPathUrl
                , QQuickPixmap::Cache | QQuickPixmap::Asynchronous);
        if (pix->isLoading())
            pix->connectFinished(this, SIGNAL(imageLoaded()));
    }
}