Important: Please read the Qt Code of Conduct -

std::istream to QByteArray

  • Can someone suggest me a way to convert a std::istream to QByteArray?

  • the question doesn't rally makes sense but anyway:

    // std::istream is;
    is.seekg (0, is.end);
    const int length = is.tellg();
    is.seekg (0, is.beg);
    QByteArray readBytes;
    readBytes.resize(length); (,length);

  • Many thanks for your quick help but seems to not work.
    After many time I have found a solution.

            std::istream &StreamIn= Session.receiveResponse(Res);
            QByteArray QBAByteIn;
            char Buffer[128];
            while (!StreamIn.eof()) {
                int BytesIn=, sizeof(Buffer)).gcount();
                QBAByteIn.append(Buffer, BytesIn);


Log in to reply