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. [SOLVED] Conversion from 'QByteArray' to 'const uchar*' is ambiguous?
QtWS25 Last Chance

[SOLVED] Conversion from 'QByteArray' to 'const uchar*' is ambiguous?

Scheduled Pinned Locked Moved General and Desktop
10 Posts 1 Posters 9.4k Views
  • 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.
  • ? This user is from outside of this forum
    ? This user is from outside of this forum
    Guest
    wrote on last edited by
    #1

    I am using the overloaded method:

    @bool QPixmap::loadFromData ( const QByteArray & data, const char * format = 0, Qt::ImageConversionFlags flags = Qt::AutoColor )@

    When I get this error. Why does Qt even try to cast the byte array to a uchar* when I am using an overload that is supposed to work directly with the byte array? I have a valid QByteArray, loaded form a file:

    @finalBrush.loadFromData(brushPrototype, QImage::Format_Indexed8);@

    finalBrush is the pixmap, brushPrototype is the byte array. Any ideas?

    Edit: I do not get the error message if I exclude the format and use the default 0, but it doesn't do me any good this way. Just noting the format has something to do with it, but I still can't find a way to resolve it. brushPrototype does indeed contain an array of 8 bit greyscale values.

    I get the feeling I am not using the format parameter properly, the image format is supposed to be an enum, and this method accepts a char * as a format parameter.

    After failing to find anything about the proper usage and format of "format" in the documentation I decided to drill into the source code so I can find usage of it. There was no direct usage of it in QPixmap, nor in QPixmapData, nor in QImageReader, the format parameter is just being passed on deeper and deeper, until I hit QImageReaderPrivate and with it a dead end...

    1 Reply Last reply
    0
    • C Offline
      C Offline
      cincirin
      wrote on last edited by
      #2

      "format" parameter is supposed to be "one of the following format":http://qt-project.org/doc/qt-4.8/qimagereader.html#supportedImageFormats

      1 Reply Last reply
      0
      • ? This user is from outside of this forum
        ? This user is from outside of this forum
        Guest
        wrote on last edited by
        #3

        Hmm... well, I don't use any of those formats, I am using a RAW image format of 8 bit grayscale values for every pixel.

        1 Reply Last reply
        0
        • C Offline
          C Offline
          cincirin
          wrote on last edited by
          #4

          You cannot construct a QPixmap in this way. Instead use "this QImage constructor":http://qt-project.org/doc/qt-4.8/qimage.html#QImage-5 and then convert to QPixmap

          Edit:

          bq. QImage is designed and optimized for I/O, and for direct pixel access and manipulation, while QPixmap is designed and optimized for showing images on screen

          1 Reply Last reply
          0
          • ? This user is from outside of this forum
            ? This user is from outside of this forum
            Guest
            wrote on last edited by
            #5

            Ok, I used exactly the same constructor, but the application crashes the moment I try to draw that image:

            @ QImage test(brushData, 100, 100, QImage::Format_Indexed8);
            painter.drawImage(location, test);@

            It locks up, and I am left with:

            bq. exited with code -1073741819

            1 Reply Last reply
            0
            • C Offline
              C Offline
              cincirin
              wrote on last edited by
              #6

              Make sure :

              bq. the buffer must remain valid throughout the life of the QImage and all copies that have not been modified or otherwise detached from the original buffer

              1 Reply Last reply
              0
              • ? This user is from outside of this forum
                ? This user is from outside of this forum
                Guest
                wrote on last edited by
                #7

                I am pretty sure, as everything happens in the same block of code, a few lines apart. I have noticed such odd problems with using QImage before. Note that it works if I create a QPixmap::fromImage, so the QImage is valid, it just crashes the app when I try to draw it.

                1 Reply Last reply
                0
                • C Offline
                  C Offline
                  cincirin
                  wrote on last edited by
                  #8

                  Also for grayscale image to see properly, need to add color table:
                  @
                  QVector<QRgb> vectorColors(256);
                  for (int c = 0; c < 256; c++)
                  vectorColors[c] = qRgb(c, c, c);

                  yourImage.setColorTable(vectorColors)
                  @

                  1 Reply Last reply
                  0
                  • C Offline
                    C Offline
                    cincirin
                    wrote on last edited by
                    #9

                    [quote author="ddriver" date="1332417697"]Note that it works if I create a QPixmap::fromImage, so the QImage is valid[/quote]

                    Where you do this conversion ? In paintEvent ? If yes, then data buffer seems to be valid, also is 32-bit aligned. I have no problem with these QImage constructor and then paint the image.

                    1 Reply Last reply
                    0
                    • ? This user is from outside of this forum
                      ? This user is from outside of this forum
                      Guest
                      wrote on last edited by
                      #10

                      Yes, it was in the paint event... anyway...

                      Thanks the color table really did the trick for me. My goal was basically this:

                      !http://i41.tinypic.com/2cp9tw7.jpg(this)!

                      Using a grayscale image as a brush stencil prototype and colorizing it with a user selected color, creating another pixmap that uses the prototype for alpha.

                      I really didn't expect this to take two hours LOL :D

                      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