[Interest] How to send an arbitrary file over sockets

Ghobad Zarrinchian gzarrin.edu at gmail.com
Sat May 30 01:29:13 CEST 2020


Dear all,
I'm writing a client/server application in which the client can send a file
to the server. At the client side, my code is something like below:

QFile fl(file_name);

fl.open(QIODevice::ReadOnly);

QByteArray fileBytes = fl.readAll();

socket->write(fileBytes);

fl.close();

And at the server side, the code that receives the file is something like this:

QByteArray data = client_socket->readAll();
QFile fl(file_name);fl.open(QIODevice::WriteOnly);fl.write(data);fl.close();

While the code above works well with text files, it does not work for
other file types (like JPG and PDF files). What is the problem? How
should i modify the code so that it works for all kinds of files?

Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20200530/270692cf/attachment.html>


More information about the Interest mailing list