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. Release memory with the QImage

Release memory with the QImage

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 4.0k 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.
  • R Offline
    R Offline
    ras123
    wrote on last edited by
    #1

    How I can clear or release memory associated witht he QImage? now I am doing like this
    @ if(!image->isNull())
    {
    delete image;
    image = new QImage;
    }@

    I know this is not a good way, but I need to get a QImage with null as shown above, so please help

    Thanking You,
    Ras

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tzander
      wrote on last edited by
      #2

      the above way is Ok, although I'm curious why you use isNull() instead of just deleting it.

      Also notice that you probably want to avoid using new/delete for QImage. Its an internally ref-counted value type.

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tobias.hunger
        wrote on last edited by
        #3

        @image = QImage();@

        should also release memory, and you do not need to make image a pointer to QImage to use it.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          Works, as long as you are certain that image is a valid pointer. Are you sure you need to use a pointer though?

          1 Reply Last reply
          0
          • R Offline
            R Offline
            ras123
            wrote on last edited by
            #5

            Thanks, I changed the pointer option, and use image = QImage() to make it a null, as said by Tobias Hunger

            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