Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. 3rd Party Software
  4. Streaming contents of QByteArray SOLVED
QtWS25 Last Chance

Streaming contents of QByteArray SOLVED

Scheduled Pinned Locked Moved 3rd Party Software
5 Posts 3 Posters 3.5k 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.
  • G Offline
    G Offline
    gpuckett54
    wrote on last edited by
    #1

    Hi, I have a 3rd party product that does map displays. I need to place images over the map using their custom Raster class. I can do this with a static fromFile function. My problem is the png images are in a resource file. The fromFile function does not recognize the resource file path. There is a fromStream function that will probably work but I can't figure out how to make it work.

    I can read the file into a QByteArray using QFile readAll. But I can't figure out how to get from there to the format this function requires. The signature of the function is:

    Raster::fromStream(uint8_t* data, uint32_t length, ImageFormat format);

    Can someone suggest what I need to do to get from QByteArray to whatever is needed to make this work?

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

      Hi,

      Something like

      @Raster::fromStream(yourByteArray.data(), yourByteArray.size(), TheCorrectEnumCorrespondingToYouData);@

      should be good

      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
      • G Offline
        G Offline
        gpuckett54
        wrote on last edited by
        #3

        Thank you for your response. I tried that. It complained about not being able to convert to the uint8_t. I've searched for days. Everything I've tried has failed. QByteArray.data() returns a char* which is not uint8_t*.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andreyc
          wrote on last edited by
          #4

          Most likely sizeof(uint8_t) is equal to sizeof(char) on your target system, so you can cast one pointer to another
          @
          Raster::fromStream(reinterpret_cast<uint8_t*>(yourByteArray.data()), yourByteArray.size(), TheCorrectEnumCorrespondingToYouData);
          @

          EDIT: static_cast does not work here. It is either reinterpret_cast or C-style (uint8_t*)data.

          1 Reply Last reply
          0
          • G Offline
            G Offline
            gpuckett54
            wrote on last edited by
            #5

            Finally got this working. Here is the code:

            @
            QByteArray star = getImage(":/images/star");
            char* starData = star.data();
            uint8_t* starData8t = (uint8_t*)starData;@

            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