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
Forum Updated to NodeBB v4.3 + New Features

problem with file format

Scheduled Pinned Locked Moved Solved General and Desktop
22 Posts 4 Posters 6.4k Views 2 Watching
  • 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.
  • M mrjj
    13 Jan 2017, 12:03

    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.

    A Offline
    A Offline
    Armin
    wrote on 13 Jan 2017, 12:40 last edited by
    #3

    @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;
    
    M J 2 Replies Last reply 13 Jan 2017, 12:43
    0
    • A Armin
      13 Jan 2017, 12:40

      @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;
      
      M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 13 Jan 2017, 12:43 last edited by mrjj
      #4

      @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?

      A 1 Reply Last reply 13 Jan 2017, 13:10
      1
      • M mrjj
        13 Jan 2017, 12:43

        @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?

        A Offline
        A Offline
        Armin
        wrote on 13 Jan 2017, 13:10 last edited by
        #5

        @mrjj Thanks
        I downloaded file and save in directory of windows , but don't run :(

        1 Reply Last reply
        0
        • V Offline
          V Offline
          VRonin
          wrote on 13 Jan 2017, 13:28 last edited by
          #6

          the problem is probably in reply->readAll(); when do you call this function?

          "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 14 Jan 2017, 08:28
          1
          • V VRonin
            13 Jan 2017, 13:28

            the problem is probably in reply->readAll(); when do you call this function?

            A Offline
            A Offline
            Armin
            wrote on 14 Jan 2017, 08:28 last edited by
            #7

            @VRonin Thanks
            In first.
            You see my code in above.

            M 1 Reply Last reply 14 Jan 2017, 09:22
            0
            • A Armin
              14 Jan 2017, 08:28

              @VRonin Thanks
              In first.
              You see my code in above.

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 14 Jan 2017, 09:22 last edited by
              #8

              @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?

              A 1 Reply Last reply 16 Jan 2017, 09:51
              2
              • M mrjj
                14 Jan 2017, 09:22

                @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?

                A Offline
                A Offline
                Armin
                wrote on 16 Jan 2017, 09:51 last edited by
                #9

                @mrjj Thanks
                when i download with download manager everything is ok,
                but when i download it my app, file have problems.

                1 Reply Last reply
                0
                • V Offline
                  V Offline
                  VRonin
                  wrote on 16 Jan 2017, 09:53 last edited by
                  #10

                  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?

                  "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 16 Jan 2017, 10:35
                  3
                  • A Armin
                    13 Jan 2017, 12:40

                    @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;
                    
                    J Offline
                    J Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on 16 Jan 2017, 10:31 last edited by
                    #11

                    @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.

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0
                    • V VRonin
                      16 Jan 2017, 09:53

                      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?

                      A Offline
                      A Offline
                      Armin
                      wrote on 16 Jan 2017, 10:35 last edited by
                      #12

                      @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.

                      J 2 Replies Last reply 16 Jan 2017, 11:44
                      0
                      • A Armin
                        16 Jan 2017, 10:35

                        @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.

                        J Offline
                        J Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on 16 Jan 2017, 11:44 last edited by
                        #13

                        @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.

                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        2
                        • A Armin
                          16 Jan 2017, 10:35

                          @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.

                          J Offline
                          J Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on 16 Jan 2017, 11:46 last edited by
                          #14

                          @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.

                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                          A 1 Reply Last reply 16 Jan 2017, 11:56
                          2
                          • J jsulm
                            16 Jan 2017, 11:46

                            @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.

                            A Offline
                            A Offline
                            Armin
                            wrote on 16 Jan 2017, 11:56 last edited by
                            #15

                            @jsulm

                            {
                                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?

                            J 1 Reply Last reply 16 Jan 2017, 12:02
                            0
                            • A Armin
                              16 Jan 2017, 11:56

                              @jsulm

                              {
                                  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?

                              J Offline
                              J Offline
                              jsulm
                              Lifetime Qt Champion
                              wrote on 16 Jan 2017, 12:02 last edited by
                              #16

                              @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 just

                              md5sum file
                              

                              https://forum.qt.io/topic/113070/qt-code-of-conduct

                              A 1 Reply Last reply 17 Jan 2017, 12:02
                              1
                              • V Offline
                                V Offline
                                VRonin
                                wrote on 16 Jan 2017, 12:19 last edited by VRonin
                                #17

                                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()), /*...*/ ?

                                "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 17 Jan 2017, 12:00
                                3
                                • V VRonin
                                  16 Jan 2017, 12:19

                                  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()), /*...*/ ?

                                  A Offline
                                  A Offline
                                  Armin
                                  wrote on 17 Jan 2017, 12:00 last edited by
                                  #18

                                  @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())));
                                  
                                  }
                                  
                                  1 Reply Last reply
                                  0
                                  • J jsulm
                                    16 Jan 2017, 12:02

                                    @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 just

                                    md5sum file
                                    
                                    A Offline
                                    A Offline
                                    Armin
                                    wrote on 17 Jan 2017, 12:02 last edited by
                                    #19

                                    @jsulm Thanks
                                    Hashes? I don't know about that

                                    J 1 Reply Last reply 17 Jan 2017, 12:28
                                    0
                                    • A Armin
                                      17 Jan 2017, 12:02

                                      @jsulm Thanks
                                      Hashes? I don't know about that

                                      J Offline
                                      J Offline
                                      jsulm
                                      Lifetime Qt Champion
                                      wrote on 17 Jan 2017, 12:28 last edited by
                                      #20

                                      @Armin Well, you can learn. I provided an example how to calculate md5 hash for a file.

                                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                                      1 Reply Last reply
                                      2
                                      • V Offline
                                        V Offline
                                        VRonin
                                        wrote on 17 Jan 2017, 12:40 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 19 Jan 2017, 12:12
                                        3
                                        • V VRonin
                                          17 Jan 2017, 12:40

                                          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 19 Jan 2017, 12:12 last edited by
                                          #22

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

                                          1 Reply Last reply
                                          0

                                          12/22

                                          16 Jan 2017, 10:35

                                          • Login

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