Important: Please read the Qt Code of Conduct -

Streaming contents of QByteArray SOLVED

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

  • Lifetime Qt Champion


    Something like

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

    should be good

  • 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. returns a char* which is not uint8_t*.

  • 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.size(), TheCorrectEnumCorrespondingToYouData);

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

  • Finally got this working. Here is the code:

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

Log in to reply