Reading a file with Qt
-
It was regarding your last remark about the server and client being in the same project. Since you are writing both, then it doesn't matter that they are in different projects.
-
Hey, everybody,
Still in the example given by the Qt documentation for the exchange of large documents between the client and the server in a chatt software, I could separate the client and the server in different projects which is not the case in the example given by the Qt documentation.
So here's my question:
Just that there I do not know how to adapt this example to my chatt software to be able to send large files between client and server?
Translated with www.DeepL.com/Translator
-
There's nothing special to do, if you implement the client and the server the same way as the exemple, then it's also going to work the same.
-
@EL-jos
Hi
As mr @Christian-Ehrlicher noted higher up.
You are using quint16 for size handling
Try
#include <limits.h>
qDebug() << std::numeric_limits<quint16>::max();and you will see the magic 65535 as maximum value.
-
Yes you are right but except that 65535 makes a maximum size of 64Ko or me I want to send voluminous documents of the order of 30Mo to even 50Mo
-
Yes you are right but except that 65535 makes a maximum size of 64Ko or me I want to send voluminous documents of the order of 30Mo to even 50Mo
@EL-jos said in Reading a file with Qt:
65535 makes a maximum size of 64Ko or me I want to send voluminous documents of the order of 30Mo to even 50Mo
Then you cannot use quint16. It is too small.
Use quint32 or even quint64 instead.
EDIT: @mrjj beat me to it!
-
Hey, everybody.
I was able to solve my problem thanks to your advice, now I am able to send large document in my chatt software but there is a new problem that arises, here is the problem: Which class should I use to send a video file in my chatt software?
Example: for image exchange, I used the class QImage(Stream for image)but now what class used for Video(Stream video)? -
Hey, everybody.
I was able to solve my problem thanks to your advice, now I am able to send large document in my chatt software but there is a new problem that arises, here is the problem: Which class should I use to send a video file in my chatt software?
Example: for image exchange, I used the class QImage(Stream for image)but now what class used for Video(Stream video)?@EL-jos If it is a file then simply send the binary content of the file.
There is no need to use a dedicated class for each and every data type.
https://stackoverflow.com/questions/30288385/how-to-send-a-file-in-qt -
Why should a file not be supported if you just send it byte-by-byte? if you store it on a harddisk, it does not matter for the hard disk which file type it is. Its just a number of bytes.
Same happens when you send it over network.
Regards
-
Yes it is already what I do so I send data in bytes but except that it does not work because I have an error when reading my file like this file is not supported
@EL-jos said in Reading a file with Qt:
error when reading my file like this file is not supported
Please explain. Where do you get this error? QFile (I guess you use it for reading) does not care at all about file content.
-
In fact after the client sends the byte array, the server receives the bytes and Opens a file in write only mode and writes all the bytes received but except that if I try via VLC to read this file, there is a message that appears like this file is not supported
-
In fact after the client sends the byte array, the server receives the bytes and Opens a file in write only mode and writes all the bytes received but except that if I try via VLC to read this file, there is a message that appears like this file is not supported
-
In fact after the client sends the byte array, the server receives the bytes and Opens a file in write only mode and writes all the bytes received but except that if I try via VLC to read this file, there is a message that appears like this file is not supported
@EL-jos
So you need to do a little detective work to help yourself.You have a file which is openable by "VLC" (whatever that is) at the client before you start, right? And you're saying after you have sent it to server it is not openable, right?
So start by using a regular file copy, outside of anything Qt, to copy the file from client to server. Make sure you keep the same filename extension. Then: Is the copied file openable on the server? Is it the same size as when you copy via Qt? Use a file content comparison tool (e.g. Windows
fc /b
), is the file content of the Qt copy identical to that of the non-Qt copy?