Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. QImage from QDatastream of float values
Qt 6.12 LTS is out! See what's new in the release blog

QImage from QDatastream of float values

Scheduled Pinned Locked Moved Unsolved C++ Gurus
4 Posts 2 Posters 1.8k Views 1 Watching
  • 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.
  • connecting_dotsC Offline
    connecting_dotsC Offline
    connecting_dots
    wrote on last edited by
    #1

    Hi all,
    I am getting image through UDP. In the payload of the frame, first 1 byte is width, and second byte is height and then image float values(32x32). Using QDataStream, I am trying to generate QImage but somehow I am not getting the correct solution. I am just stuck for converting and reading the the float values.

    QDataStream out(udpdata);
    out. setByteOrder(QDataStream::LittleEndian);
    out.setFloatingPointPrecesion(QDataStream::SinglePrecision);
    quint8 width, height;
    out >> width, height;
    int pixel= widthheight;
    temp
    float =new floatpixel;
    QByteArray buffer;
    int index=0;
    out.readbytes(temp,pixel);
    buffer.append(temp, pixel);
    QImage image(width, height, QImage::Format_RGB32);
    for(int i=0; i<=(pixel-1); ++i; ++index)
    image.bits() [index] = buffer[i];
    image.save(image, “PNG”);
    delete temp;

    Also, I am getting different images from UDP, so the size of the image is not fixed every time.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      QImage doesn't support floating point types. Did you convert it before sending it ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      connecting_dotsC 1 Reply Last reply
      2
      • SGaistS SGaist

        Hi and welcome to devnet,

        QImage doesn't support floating point types. Did you convert it before sending it ?

        connecting_dotsC Offline
        connecting_dotsC Offline
        connecting_dots
        wrote on last edited by
        #3

        @SGaist Thanks. I am trying to convert it into quint32 but still not working out for me. I guess, I am getting confused in extracting each float value from datastream. Also readRawdata and readBytes only supports char s it gives me error saying invalid conversion.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          What kind of images are that in the first place ?
          Where do they come from ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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