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. QFile writing more than 32mb at once crashes under windows 32bit

QFile writing more than 32mb at once crashes under windows 32bit

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 5 Posters 960 Views 4 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.
  • GGAllinG Offline
    GGAllinG Offline
    GGAllin
    wrote on last edited by
    #1

    Hello everyone!
    I have updated my appqt from 5.6 to 5.12.

    Before the migration this method works fine

    bool writeFile(QFile& file, QByteArray data)
    {
       int bufferSize  = 30 * 1024 * 1024; 
        auto bufferSegment = data.left(bufferSize);
        while (!bufferSegment.isEmpty()) {
            qApp->processEvents();
            file.write(bufferSegment);
            data.remove(0, bufferSegment.size());
            bufferSegment = data.left(bufferSize);
        }
        return true;
    }
    
    
     const QString absPath = baseDir.absoluteFilePath(fi.filePath);
            QFileInfo temp_fi(absPath);
            QDir().mkpath(temp_fi.dir().absolutePath());
            writeFile(absPath, fileData(fi.filePath));
    
    QByteArray fileData(const &QString fileName)const {
          // other code here
     } 
    

    After the update, my application are crashing again.

    Any ideas?
    Thanks in advanced and sorry for my bad english
    GG.

    kshegunovK 1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      HI
      What lines does it crash in ?
      Code looks ok.

      1 Reply Last reply
      1
      • Kent-DorfmanK Offline
        Kent-DorfmanK Offline
        Kent-Dorfman
        wrote on last edited by
        #3

        @GGAllin said in QFile writing more than 32mb at once crashes under windows 32bit:

        bool writeFile(QFile& file, QByteArray data)

        Are you sure that you want to pass that by value?

        If you meet the AI on the road, kill it.

        mrjjM 1 Reply Last reply
        1
        • Kent-DorfmanK Kent-Dorfman

          @GGAllin said in QFile writing more than 32mb at once crashes under windows 32bit:

          bool writeFile(QFile& file, QByteArray data)

          Are you sure that you want to pass that by value?

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Kent-Dorfman
          Its implicitly shared so not that expensive but good eye :)
          https://doc.qt.io/qt-5/implicit-sharing.html

          Kent-DorfmanK 1 Reply Last reply
          0
          • mrjjM mrjj

            @Kent-Dorfman
            Its implicitly shared so not that expensive but good eye :)
            https://doc.qt.io/qt-5/implicit-sharing.html

            Kent-DorfmanK Offline
            Kent-DorfmanK Offline
            Kent-Dorfman
            wrote on last edited by Kent-Dorfman
            #5

            @mrjj

            but what might data.remove() do to it then? Also, what about the size of the object if it is passed on the stack? I envision bad thing happening when you pass huge arrays on the window stack.

            If you meet the AI on the road, kill it.

            mrjjM JonBJ 2 Replies Last reply
            0
            • Kent-DorfmanK Kent-Dorfman

              @mrjj

              but what might data.remove() do to it then? Also, what about the size of the object if it is passed on the stack? I envision bad thing happening when you pass huge arrays on the window stack.

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Kent-Dorfman
              You are right, it should produce a copy since its modified.

              1 Reply Last reply
              0
              • Kent-DorfmanK Kent-Dorfman

                @mrjj

                but what might data.remove() do to it then? Also, what about the size of the object if it is passed on the stack? I envision bad thing happening when you pass huge arrays on the window stack.

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by
                #7

                @Kent-Dorfman

                but what might data.remove() do to it then?

                Correct. But then passing the QByteArray in by reference, the usual thing to do, is going to alter it in the caller, which we can't have. So really the approach taken for buffering needs to be rethought. QIODevice::write(const char *data, qint64 maxSize) looks like the better overload to utilize.

                None of which addresses @GGAllin's issue. AS @mrjj asked, where exactly does it crash? If you reduce the buffer size does it make any difference?

                1 Reply Last reply
                0
                • GGAllinG GGAllin

                  Hello everyone!
                  I have updated my appqt from 5.6 to 5.12.

                  Before the migration this method works fine

                  bool writeFile(QFile& file, QByteArray data)
                  {
                     int bufferSize  = 30 * 1024 * 1024; 
                      auto bufferSegment = data.left(bufferSize);
                      while (!bufferSegment.isEmpty()) {
                          qApp->processEvents();
                          file.write(bufferSegment);
                          data.remove(0, bufferSegment.size());
                          bufferSegment = data.left(bufferSize);
                      }
                      return true;
                  }
                  
                  
                   const QString absPath = baseDir.absoluteFilePath(fi.filePath);
                          QFileInfo temp_fi(absPath);
                          QDir().mkpath(temp_fi.dir().absolutePath());
                          writeFile(absPath, fileData(fi.filePath));
                  
                  QByteArray fileData(const &QString fileName)const {
                        // other code here
                   } 
                  

                  After the update, my application are crashing again.

                  Any ideas?
                  Thanks in advanced and sorry for my bad english
                  GG.

                  kshegunovK Offline
                  kshegunovK Offline
                  kshegunov
                  Moderators
                  wrote on last edited by
                  #8

                  @GGAllin said in QFile writing more than 32mb at once crashes under windows 32bit:

                  After the update, my application are crashing again.

                  Please provide a stack trace.

                  Read and abide by the Qt Code of Conduct

                  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