2017-10-17 91 views
-2

在qtQuick源代碼中。有一個在功能的LoadImage一行代碼:qtQuick源代碼中的loadImage函數

QQuickPixmap* pix = new QQuickPixmap(); 

如果我儘可能多地調用這個函數在操作系統這個應用程序分配的內存canvas.The將填補,這將導致圖片失敗。我想問一下這個源代碼是否有問題?

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

回答

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