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

Problem with deleting QBuffer

Scheduled Pinned Locked Moved Solved General and Desktop
18 Posts 4 Posters 1.1k 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
    #2

    Where do you initialize file and buffer in the ctors? You currently only initialize them in one of the ctors.
    Also I don't see a reason why QFile and QBuffer should be created with new instead using plain objects in the class.

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

    SGaistS A 2 Replies Last reply
    0
    • Christian EhrlicherC Christian Ehrlicher

      Where do you initialize file and buffer in the ctors? You currently only initialize them in one of the ctors.
      Also I don't see a reason why QFile and QBuffer should be created with new instead using plain objects in the class.

      SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #3

      @Christian-Ehrlicher they are initialized at declaration time to nullptr.

      That said, there's indeed no use for pointers here.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      Christian EhrlicherC 1 Reply Last reply
      0
      • Christian EhrlicherC Christian Ehrlicher

        Where do you initialize file and buffer in the ctors? You currently only initialize them in one of the ctors.
        Also I don't see a reason why QFile and QBuffer should be created with new instead using plain objects in the class.

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

        @Christian-Ehrlicher said in Problem with deleting QBuffer:

        Where do you initialize file and buffer in the ctors? You currently only initialize them in one of the ctors.
        Also I don't see a reason why QFile and QBuffer should be created with new instead using plain objects in the class.

        I want the class to handle EITHER QFile OR QBuffer. Because of this, I decided to make them pointers to save some memory.

        UPD: I remade the code so it doesn't use pointers in the FileHandler class. It didn't help. Still the same error.

        Christian EhrlicherC 1 Reply Last reply
        0
        • SGaistS SGaist

          @Christian-Ehrlicher they are initialized at declaration time to nullptr.

          That said, there's indeed no use for pointers here.

          Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by Christian Ehrlicher
          #5

          @SGaist said in Problem with deleting QBuffer:

          they are initialized at declaration time to nullptr.

          Where do you see this?
          Now there is also the header... hmm

          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 aiphae

            @Christian-Ehrlicher said in Problem with deleting QBuffer:

            Where do you initialize file and buffer in the ctors? You currently only initialize them in one of the ctors.
            Also I don't see a reason why QFile and QBuffer should be created with new instead using plain objects in the class.

            I want the class to handle EITHER QFile OR QBuffer. Because of this, I decided to make them pointers to save some memory.

            UPD: I remade the code so it doesn't use pointers in the FileHandler class. It didn't help. Still the same error.

            Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #6

            @aiphae said in Problem with deleting QBuffer:

            . Still the same error.

            Please provide some minimal, compilable code and a proper backtrace.

            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

              @aiphae said in Problem with deleting QBuffer:

              . Still the same error.

              Please provide some minimal, compilable code and a proper backtrace.

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

              @Christian-Ehrlicher said in Problem with deleting QBuffer:

              @aiphae said in Problem with deleting QBuffer:

              . Still the same error.

              Please provide some minimal, compilable code and a proper backtrace.

              Maybe this:

              FileHandler *csvHandler = nullptr;
              QVector<QString> files = {"path_1", "path_2"};
              
              for (const auto &path: files) {
                  FileHandler *newHandler = nullptr;
                  newHandler = new FileHandler(QFile(path).readAll);
                  delete csvHandler;
                  csvHandler = newHandler;
              }
              

              FileHandler.h and FileHandler.cpp are above.

              1 Reply Last reply
              0
              • 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