Important: Please read the Qt Code of Conduct -

Release memory with the QImage

  • 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,

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

  • Moderators

    @image = QImage();@

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

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

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

Log in to reply