problem with file format
-
Hi
How do you convert it to mp4 format?
Do you load a mp4 file and then save it some other place?Please show code for what you do.
-
Hi
How do you convert it to mp4 format?
Do you load a mp4 file and then save it some other place?Please show code for what you do.
-
@mrjj Thanks
QByteArray ba = reply->readAll(); QString filename="C:/Users/armin/Desktop/New folder.mp4"; QFile file(filename); file.open(QIODevice::WriteOnly); QDataStream out(&file); out << ba;
@Armin
Hi That will save what ever you get from reply->readAll();
directly to a file.
So unless it WAS mp4 format to begin with, all you did was to save the
bytes directly from the readAll()So Question 1 is
Is the file you are READING already mp4 ?
Are you are downloading a MP4 file and try to save it later? -
@Armin
Hi That will save what ever you get from reply->readAll();
directly to a file.
So unless it WAS mp4 format to begin with, all you did was to save the
bytes directly from the readAll()So Question 1 is
Is the file you are READING already mp4 ?
Are you are downloading a MP4 file and try to save it later? -
@Armin
Hi
Did you try to download the file normally and check that it can play ?
Also did you compare the size of the file when u saved it ?
How many bytes compared to the orginal file? -
QByteArray ba = reply->readAll();
QString filename="C:/Users/armin/Desktop/New folder.mp4";
QFile file(filename);
file.open(QIODevice::WriteOnly);
QDataStream out(&file);
out << ba;I do not think the problem is here but rather in where you call this from. Is this connected to a QNetworkReply?
-
@mrjj Thanks
QByteArray ba = reply->readAll(); QString filename="C:/Users/armin/Desktop/New folder.mp4"; QFile file(filename); file.open(QIODevice::WriteOnly); QDataStream out(&file); out << ba;
@Armin said in problem with file format:
QByteArray ba = reply->readAll();
QString filename="C:/Users/armin/Desktop/New folder.mp4";
QFile file(filename);
file.open(QIODevice::WriteOnly);
QDataStream out(&file);
out << ba;readAll() does not necessarily return the whole file at once!
You need to call readAll() each time you get data over network (see http://doc.qt.io/qt-5/qiodevice.html#readyRead) and APPEND that data to the file. -
QByteArray ba = reply->readAll();
QString filename="C:/Users/armin/Desktop/New folder.mp4";
QFile file(filename);
file.open(QIODevice::WriteOnly);
QDataStream out(&file);
out << ba;I do not think the problem is here but rather in where you call this from. Is this connected to a QNetworkReply?
-
@VRonin
i don't have any problem with saving file,
file will be saved correctly.
size is also correct , i just don't know why file will not execute.@Armin If the file is not working then it is broken (even if the size is same). Did you try to compare both files (binary diff)? For example you can calculate a hash for each file and if those hashes are different then file content is not the same.
-
@VRonin
i don't have any problem with saving file,
file will be saved correctly.
size is also correct , i just don't know why file will not execute. -
@Armin Another idea: do you close the file after writing? If not and your app is still running then maybe the video-player cannot play it because the file is open in your application.
-
{ QByteArray ba = reply->readAll(); QString filename="C:/Users/armin/Desktop/New folder.mp4"; QFile file(filename); file.open(QIODevice::ReadWrite); QDataStream out(&file); out << ba; file.close(); }
I accomplished. is it true?
-
file.open(QIODevice::ReadWrite);
try with
file.open(QIODevice::WriteOnly);
You still haven't answered what
reply
is and when this block of code gets called.do you have something like
connect(reply,SIGNAL(readyRead()), /*...*/
?@VRonin Thanks
void MainWindow::on_pushButton_clicked() { QNetworkAccessManager *manager = new QNetworkAccessManager(this); connect(manager , SIGNAL(finished(QNetworkReply*)) , this , SLOT(replyFinished(QNetworkReply*))); manager->get(QNetworkRequest(QUrl(ui->textEdit->toPlainText()))); }
-
@Armin file.close() is not needed as QFile instance is a local variable and closes the file automatically when it goes out of scope. But you can try.
Did you try to calculate hashes?
On Linux it would be justmd5sum file