title: QImage: How to destroy pointer to pixels data properly?
body: <p>In my main class that controls a window, I have this function, where <code>pixmapItem</code> is a <code>QGraphicsPixmapItem*</code> defined in the class header:</p>
  
  <pre><code>void updateDisplay() {
      uchar *data = new ...; // array of pixel data
      ...
      QImage image = QImage(data, width, height,
                            width, QImage::Format_Indexed8);
  
      pixmapItem-&gt;setPixmap(QPixmap::fromImage(image));
  }
  </code></pre>
  
  <p>My question is: How can I destroy <code>data</code> when it is not needed anymore? "Not needed anymore" means that the function above or another function in my class sets the pixmap to another image.</p>
  
  <p>I have seen that QImage has cleanup functions that may help, but the documentation is not really clear on how to use them and how to pass parameters such as the data pointer of the image to delete.</p>