How to judge class object is null ?
Unsolved
General and Desktop
-
TileItem::TileItem(QGraphicsItem *parent) : QGraphicsPixmapItem(parent) { } TileItem::TileItem(QString &surl) { setPixmapFormUrl(surl); } void TileItem::setPixmapFormUrl(QString surl) { QNetworkAccessManager *NAM = new QNetworkAccessManager; QNetworkRequest request; request.setUrl(QUrl(surl)); NAM->get(request); connect(NAM, &QNetworkAccessManager::finished, [=](QNetworkReply *reply){ QPixmap pixmap; pixmap.loadFromData(reply->readAll()); //if(TileItem) setPixmap(pixmap);//if it is deleted in parent, here will crash. NAM->deleteLater(); }); }
-
@sonichy hi,
I would say that your design has issues. Creating a QNAM for each tile when you want to a remote image is rather wasteful.
You should rather have a dedicated class that manages the retrieval of the images and setting them on the appropriate tile. That way you can also cancel the retrieval on tile deletion.