QFile Read Binary blockwise

  • Hello everyone,

    I'm trying to send files via a TcpSocket connection.
    Client and server programs are so far finished.
    I can send text-files of any size without problem, that part works fine.

    But I get unreadable files if it is any other file-format like png/bmp or a sqlitedb is transfered.
    So, I'm guessing, I don't read the file correctly?

    Reading and writing basicly breaks done to this:

    //Reading the File
    qint64 qiSend;
    int iSend = 65525; //2 byte int = 0 - 65 535 //10 Byte For tcp-header
    char readData[65525];
    qiSend = file.read(readData,iSend);
    //Writing to file
    QByteArray baWrite;
                bytesWritten =writeFile.write(baWrite);
                if(bytesWritten != baWrite.size())
                    qDebug() << "could not write all bytes" << bytesWritten << "of" << baWrite.size();

    Anyone an idea, what I'm doing wrong?

  • Never mind,
    @tobias-hunger in this thread 6 years ago is right.

    I changed:

    qiSend = file.read(readData,iSend);


    QByteArray b = file.read(iSend);

    And now I'm getting all needed bytes.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.