problem with file format
-
QNetworkAccessManager should usually not be built and destroyed every time, you are also leaking memory.
- add
QNetworkAccessManager* m_manager;
as a private member inMainWindow
- in MainWindow constructor add
m_manager=new QNetworkAccessManager(this); connect(manager , SIGNAL(finished(QNetworkReply*)) , this , SLOT(replyFinished(QNetworkReply*)));
- change MainWindow::on_pushButton_clicked() into:
void MainWindow::on_pushButton_clicked() { m_manager->get(QNetworkRequest(QUrl(ui->textEdit->toPlainText()))); }
- change
replyFinished
into:
void MainWindow::replyFinished(QNetworkReply* reply){ Q_ASSERT(reply); QFile file("C:/Users/armin/Desktop/" + reply->url().fileName()); if(file.open(QIODevice::WriteOnly)) file.write(reply->readAll()); else qDebug("Save Failed"); reply->deleteLater(); }
P.S.
You are downloading videos, buffering them all in memory before saving them to disk might be a stretch for the RAM of a low-spec PC, dump the data to file as it comes along to prevent running out of memory, see https://forum.qt.io/topic/74397/how-can-i-write-any-data-on-directory/10 - add
-
QNetworkAccessManager should usually not be built and destroyed every time, you are also leaking memory.
- add
QNetworkAccessManager* m_manager;
as a private member inMainWindow
- in MainWindow constructor add
m_manager=new QNetworkAccessManager(this); connect(manager , SIGNAL(finished(QNetworkReply*)) , this , SLOT(replyFinished(QNetworkReply*)));
- change MainWindow::on_pushButton_clicked() into:
void MainWindow::on_pushButton_clicked() { m_manager->get(QNetworkRequest(QUrl(ui->textEdit->toPlainText()))); }
- change
replyFinished
into:
void MainWindow::replyFinished(QNetworkReply* reply){ Q_ASSERT(reply); QFile file("C:/Users/armin/Desktop/" + reply->url().fileName()); if(file.open(QIODevice::WriteOnly)) file.write(reply->readAll()); else qDebug("Save Failed"); reply->deleteLater(); }
P.S.
You are downloading videos, buffering them all in memory before saving them to disk might be a stretch for the RAM of a low-spec PC, dump the data to file as it comes along to prevent running out of memory, see https://forum.qt.io/topic/74397/how-can-i-write-any-data-on-directory/10 - add