Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. problem with file format
QtWS25 Last Chance

problem with file format

Scheduled Pinned Locked Moved Solved General and Desktop
22 Posts 4 Posters 5.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • VRoninV Offline
    VRoninV Offline
    VRonin
    wrote on last edited by VRonin
    #21

    QNetworkAccessManager should usually not be built and destroyed every time, you are also leaking memory.

    • add QNetworkAccessManager* m_manager; as a private member in MainWindow
    • 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

    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
    ~Napoleon Bonaparte

    On a crusade to banish setIndexWidget() from the holy land of Qt

    A 1 Reply Last reply
    3
    • VRoninV VRonin

      QNetworkAccessManager should usually not be built and destroyed every time, you are also leaking memory.

      • add QNetworkAccessManager* m_manager; as a private member in MainWindow
      • 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

      A Offline
      A Offline
      Armin
      wrote on last edited by
      #22

      @VRonin
      Thank you
      Very nice
      Thanks for answer
      my problem is solve
      :))))))))))))))))))))))))))))))))))

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved