QFile Read Binary blockwise
Solved
General and Desktop
-
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; ... if(writeFile.isOpen()){ 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);
to
QByteArray b = file.read(iSend);
And now I'm getting all needed bytes.