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 deleting QBuffer
Qt 6.11 is out! See what's new in the release blog

Problem with deleting QBuffer

Scheduled Pinned Locked Moved Solved General and Desktop
18 Posts 4 Posters 2.3k 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.
  • Christian EhrlicherC Offline
    Christian EhrlicherC Offline
    Christian Ehrlicher
    Lifetime Qt Champion
    wrote on last edited by
    #8

    This does not crash for me:

    int main(int argc, char** argv)
    {
        QApplication a(argc, argv);
        FileHandler* csvHandler = nullptr;
        QVector<QString> files = { "existing_file1.txt", "existing_file2.txt" };
        for (const auto& path : files) {
            QFile f(path);
            f.open(QIODevice::ReadOnly);
            auto newHandler = new FileHandler(f.readAll());
            delete csvHandler;
            csvHandler = newHandler;
        }
        delete csvHandler;
        return 0;
    }
    

    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
    Visit the Qt Academy at https://academy.qt.io/catalog

    A 1 Reply Last reply
    0
    • Christian EhrlicherC Christian Ehrlicher

      This does not crash for me:

      int main(int argc, char** argv)
      {
          QApplication a(argc, argv);
          FileHandler* csvHandler = nullptr;
          QVector<QString> files = { "existing_file1.txt", "existing_file2.txt" };
          for (const auto& path : files) {
              QFile f(path);
              f.open(QIODevice::ReadOnly);
              auto newHandler = new FileHandler(f.readAll());
              delete csvHandler;
              csvHandler = newHandler;
          }
          delete csvHandler;
          return 0;
      }
      
      A Offline
      A Offline
      aiphae
      wrote on last edited by aiphae
      #9

      @Christian-Ehrlicher

      That's interesting. In my code I tried to replace newHandler = new FileHandler(file.readAll(), zipFilename); with newHandler = new FileHandler(file.readAll()); (without specifying a filename). No crash now. So the issue is not in QBuffer.

      zipFilename is QString zipFilename = zip.getCurrentFileName();. I don't understand what's wrong...

      1 Reply Last reply
      0
      • A Offline
        A Offline
        aiphae
        wrote on last edited by aiphae
        #10

        @Christian-Ehrlicher

        Please try this:

        int main(int argc, char** argv)
        {
            QApplication a(argc, argv);
            FileHandler* csvHandler = nullptr;
            QVector<QString> files = { "existing_file1.txt", "existing_file2.txt" };
            for (const auto& path : files) {
                QFile f(path);
                f.open(QIODevice::ReadOnly);
                auto newHandler = new FileHandler(f.readAll(), path);
                delete csvHandler;
                csvHandler = newHandler;
            }
            delete csvHandler;
            return 0;
        }
        

        In this case the error should appear.

        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #11

          No crash here and I also don't see a reason why it should crash.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          0
          • A Offline
            A Offline
            aiphae
            wrote on last edited by
            #12

            Well it crashes when I'm specifying path and it doesn't when I don't... It's weird.

            1 Reply Last reply
            0
            • Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #13

              As I said before - please post the stacktrace.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              A 1 Reply Last reply
              0
              • Christian EhrlicherC Christian Ehrlicher

                As I said before - please post the stacktrace.

                A Offline
                A Offline
                aiphae
                wrote on last edited by
                #14

                @Christian-Ehrlicher

                This?
                e52fc7ec-9108-4e42-aa14-ea8c4e746287-image.png

                1 Reply Last reply
                0
                • Christian EhrlicherC Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #15

                  You are most likely mixing debug and release libs - I would guess you link your debug app against Qt release libs. This is not supported on windows due to different msvc runtimes.

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  A 1 Reply Last reply
                  3
                  • Christian EhrlicherC Christian Ehrlicher

                    You are most likely mixing debug and release libs - I would guess you link your debug app against Qt release libs. This is not supported on windows due to different msvc runtimes.

                    A Offline
                    A Offline
                    aiphae
                    wrote on last edited by
                    #16

                    @Christian-Ehrlicher said in Problem with deleting QBuffer:

                    You are most likely mixing debug and release libs - I would guess you link your debug app against Qt release libs. This is not supported on windows due to different msvc runtimes.

                    Is there a workaround?

                    I tried this on a release version and it's working well. But what if I want to debug it?

                    Pl45m4P 1 Reply Last reply
                    0
                    • A aiphae

                      @Christian-Ehrlicher said in Problem with deleting QBuffer:

                      You are most likely mixing debug and release libs - I would guess you link your debug app against Qt release libs. This is not supported on windows due to different msvc runtimes.

                      Is there a workaround?

                      I tried this on a release version and it's working well. But what if I want to debug it?

                      Pl45m4P Offline
                      Pl45m4P Offline
                      Pl45m4
                      wrote on last edited by
                      #17

                      @aiphae said in Problem with deleting QBuffer:

                      Is there a workaround?

                      I tried this on a release version and it's working well. But what if I want to debug it?

                      Simple: Link you release build to Qt release libs and your app's debug build to Qt's debug libs.

                      How did you install Qt?
                      You should have them.


                      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                      ~E. W. Dijkstra

                      A 1 Reply Last reply
                      2
                      • Pl45m4P Pl45m4

                        @aiphae said in Problem with deleting QBuffer:

                        Is there a workaround?

                        I tried this on a release version and it's working well. But what if I want to debug it?

                        Simple: Link you release build to Qt release libs and your app's debug build to Qt's debug libs.

                        How did you install Qt?
                        You should have them.

                        A Offline
                        A Offline
                        aiphae
                        wrote on last edited by
                        #18

                        @Pl45m4 said in Problem with deleting QBuffer:

                        Simple: Link you release build to Qt release libs and your app's debug build to Qt's debug libs.

                        Yes. Apparently I was linking external release libraries instead of debug ones. The issue is solved. Thank you!

                        1 Reply Last reply
                        0
                        • A aiphae has marked this topic as solved on

                        • Login

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