Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-40282

QPixmap QPixmap::fromImage(QImage && image, Qt::ImageConversionFlags flags = Qt::AutoColor) overwrites source image

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P1: Critical
    • Resolution: Done
    • Affects Version/s: 5.3.0, 5.3.1
    • Fix Version/s: 5.3.2
    • Labels:
      None
    • Environment:
      VS 2013, gcc
    • Commits:
      b0d0a2680afffe02713ee4110c7996ee423c1d1e

      Description

      Looking into the documentation this seems to be intended.
      But it's extremely dangerous and quite unpredictable.
      The behavior also seems to be compiler dependent!

      Asume that you have a function that returns a QImage. "test.png" is RGBA8888 but has no transparent pixels. The format could be RGB888 but is set to RGBA8888

      static QImage getImage()
      {
         static QImage img;
         if(img.isNull())
         {
            img = QImage("test.png");
            img.setFormat(Qt::RGBA8888);
         }
         return img;
      }
      

      The following code does not change the value of the static "img":

      void test1()
      {
          QImage image = getImage();
          QPixmap pixmap = QPixmap::fromImage(imgage);
      }
      

      This code changes the value of the static "img":

      void test2()
      {
          QPixmap pixmap = QPixmap::fromImage(getImage());
      }
      

      At least when compiled with Visual Studio.
      It seems that gcc does not change the value of "img".

      Please do not create functions that behave compiler dependent and are completely unpredictable!

        Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            Assignee:
            allan.jensen Allan Sandfeld Jensen
            Reporter:
            andreasloew Andreas Loew
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes