title: cv::Mat to QImage conversion
body: <p>I've found very similiar topic: <a href="https://stackoverflow.com/questions/5026965/how-to-convert-an-opencv-cvmat-to-qimage">how to convert an opencv cv::Mat to qimage</a> , but it does not solve my problem.</p>
  
  <p>I have function converting cv::Mat to QImage</p>
  
  <pre><code>QImage cvMatToQImg(cv::Mat&amp; mat)
  {
      cv::Mat rgb;
      if(mat.channels()==1)
      {
          cv::cvtColor(mat,rgb,CV_GRAY2BGR);
          cv::cvtColor(rgb,rgb,CV_BGR2BGRA);
          QImage temp = QImage((unsigned char*)(rgb.data), rgb.cols, 
                                rgb.rows,QImage::Format_ARGB32 );
  
          QImage returnImage = temp.copy();
          return returnImage;
  }
  </code></pre>
  
  <p>And it's works for my but I want to make it more efficient.
  First: why changing 2 cvtColor functions with:</p>
  
  <pre><code>cv::cvtColor(mat,rgb,CV_GRAY2BGRA)
  </code></pre>
  
  <p>fails on </p>
  
  <pre><code>QImage returnImage = temp.copy() 
  </code></pre>
  
  <p>with segfault.</p>
  
  <p>Then how to eliminate copying of QImage. When I simply return temp image, I'm getting segfault.</p>
  
  <p>Any other optimalizations can be done there? It's very often used function so I want to make it as fast as possible.</p>