Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to judge class object is null ?

How to judge class object is null ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 234 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sonichy
    wrote on 25 Sept 2020, 15:20 last edited by sonichy
    #1
    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();
        });
    }
    

    https://github.com/sonichy

    S 1 Reply Last reply 25 Sept 2020, 18:19
    0
    • V Offline
      V Offline
      VRonin
      wrote on 25 Sept 2020, 15:31 last edited by
      #2

      Not sure I understand the question...

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      0
      • S sonichy
        25 Sept 2020, 15:20
        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();
            });
        }
        
        S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 25 Sept 2020, 18:19 last edited by
        #3

        @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.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        2

        1/3

        25 Sept 2020, 15:20

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved