Problem with deleting QBuffer
-
Where do you initialize
file
andbuffer
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 withnew
instead using plain objects in the class. -
Where do you initialize
file
andbuffer
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 withnew
instead using plain objects in the class.@Christian-Ehrlicher they are initialized at declaration time to nullptr.
That said, there's indeed no use for pointers here.
-
Where do you initialize
file
andbuffer
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 withnew
instead using plain objects in the class.@Christian-Ehrlicher said in Problem with deleting QBuffer:
Where do you initialize
file
andbuffer
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 withnew
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-Ehrlicher they are initialized at declaration time to nullptr.
That said, there's indeed no use for pointers here.
@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 -
@Christian-Ehrlicher said in Problem with deleting QBuffer:
Where do you initialize
file
andbuffer
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 withnew
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.
@aiphae said in Problem with deleting QBuffer:
. Still the same error.
Please provide some minimal, compilable code and a proper backtrace.
-
@aiphae said in Problem with deleting QBuffer:
. Still the same error.
Please provide some minimal, compilable code and a proper backtrace.
@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.
-
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; }
-
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; }
That's interesting. In my code I tried to replace
newHandler = new FileHandler(file.readAll(), zipFilename);
withnewHandler = 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... -
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.
-
No crash here and I also don't see a reason why it should crash.
-
As I said before - please post the stacktrace.
-
As I said before - please post the stacktrace.
This?
-
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.
-
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.
@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?
-
@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?
@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. -
@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.@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!
-