Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Unsolved How to judge class object is null ?

    General and Desktop
    3
    3
    86
    Loading More Posts
    • 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.
    • sonichy
      sonichy last edited by sonichy

      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

      SGaist 1 Reply Last reply Reply Quote 0
      • VRonin
        VRonin last edited by

        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 Reply Quote 0
        • SGaist
          SGaist Lifetime Qt Champion @sonichy last edited by

          @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 Reply Quote 2
          • First post
            Last post