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. QPixmap: Are resources automatically shared for the same path?
Forum Updated to NodeBB v4.3 + New Features

QPixmap: Are resources automatically shared for the same path?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 300 Views 1 Watching
  • 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.
  • U Offline
    U Offline
    UpsJustInhaledQt
    wrote on last edited by
    #1

    Hello,

    I know that in the following code, not the entire image is copied, but Pix2 refers to the data of Pix1 with copy-on-write semantics:

    QPixmap Pix1(":/some/path");
    QPixmap Pix2 = Pix1;
    

    What I am interested in is, does the same apply to the following:

    QPixmap Pix1(":/some/path");
    QPixmap Pix2(":/some/path");  // uses exact same path to resource file
    

    Thank you in advance!

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      it does have
      https://doc.qt.io/qt-5/qpixmap.html#cacheKey
      which suggest Qt uses
      https://doc.qt.io/qt-5/qpixmapcache.html#details
      internally.
      However, i never really tested if its loaded from cache or from res again.
      But I dont know if fetching from cache would use the implicit sharing or return a
      "full" QPixmap.

      1 Reply Last reply
      2
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @mrjj: better quote QPixmap::load():

        Note that QPixmaps are automatically added to the QPixmapCache when loaded from a file in main thread; the key used is internal and cannot be acquired.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        3
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          :)
          And a note to self. Check the docs..
          Thanks.

          1 Reply Last reply
          0
          • U Offline
            U Offline
            UpsJustInhaledQt
            wrote on last edited by
            #5

            Thank you for your helpful replies. I believe this answers my question.

            1 Reply Last reply
            0

            • Login

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