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. Constantly generating QPixmap* fails after a number of iterations

Constantly generating QPixmap* fails after a number of iterations

Scheduled Pinned Locked Moved General and Desktop
qpixmapqhashqimage
4 Posts 2 Posters 1.7k 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
    skats
    wrote on 2 Sept 2015, 16:03 last edited by
    #1

    I am using the following code in order to generate QPixmap* pointers and then insert them into QHash<QString, QPixmap*> (I will show only the pointers generation code since this is the one that fails).

    QPixmap* MyClass::loadImg(QString fileName)
    {
         QImage qimage(fileName);
         if (qimage.isNull()) {
             qDebug() << "Cannot load image " <<  fileName;
         }
    
         QPixmap *image = new QPixmap(fileName);
         return image;
    }
    

    The problem that I have is the following: For the first about 200 calls the method works fine - it is being called on a loop that iterates through the image files of a directory. Then suddenly the QPixmap* starts returning QPixmap(null) for no apparent reason.QImage is also null when that happens. I have checked and made sure that the path is fine. Also, I have tried with various sets of images and the same always happens - it runs with no problems the ~200 calls and then starts generating nulls.

    Any help would be appreciated.

    Thank you.

    P.S. I have also posted the question on stackoverflow: http://stackoverflow.com/questions/32357815/constantly-generating-qpixmap-fails-after-a-number-of-iterations

    1 Reply Last reply
    0
    • S Offline
      S Offline
      skats
      wrote on 2 Sept 2015, 16:37 last edited by
      #2

      Now that I run it again, QImage is not null. Only the QPixMap* image is null.
      However I still cannot find what is wrong.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        skats
        wrote on 2 Sept 2015, 17:17 last edited by
        #3

        Someone replied on the stackoverflow and told me to use non-pointer variables for the QPixmaps that I generate. This has now fixed my problem. Thank you.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          alex_malyu
          wrote on 2 Sept 2015, 18:36 last edited by
          #4

          Just don't create it on heap. QPixmap is implicitly shared.

          It does not matter how you create pixmap. What does is total number of allocated resources.
          Changes to your code might fix something if your previous code did not clean the memory -did not delete pixmap.
          So code causing problem was not posted.

          1 Reply Last reply
          0

          2/4

          2 Sept 2015, 16:37

          • Login

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