std::filesystem crashes my app
-
I am trying to create a simple program using std::filesystem but my app is always crashing. I am on window using GCC 10.3.0, Qt 6.1.2.
#include <QApplication> #include <fstream> #include <filesystem> // Driver program to test the above function int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); namespace fs = std::filesystem; std::ofstream of("teststxt"); for(auto const& iter : fs::directory_iterator("binf")) { if(fs::is_regular_file(iter)) of << iter.path().filename().string() << std::endl; } of.close(); return a.exec(); }
If I comment out the code that uses std::filesystem it works fines.
-
I am trying to create a simple program using std::filesystem but my app is always crashing. I am on window using GCC 10.3.0, Qt 6.1.2.
#include <QApplication> #include <fstream> #include <filesystem> // Driver program to test the above function int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); namespace fs = std::filesystem; std::ofstream of("teststxt"); for(auto const& iter : fs::directory_iterator("binf")) { if(fs::is_regular_file(iter)) of << iter.path().filename().string() << std::endl; } of.close(); return a.exec(); }
If I comment out the code that uses std::filesystem it works fines.
-
@hbatalha
Well it doesn't look like whatever it is has anything to do with Qt. When you run in debugger what is the stack trace on "crash"?Well it doesn't look like whatever it is has anything to do with Qt.
I ran this code in Code::Blocks and it worked fine. It does look like it has to do with Qt. But I will do some more digging and what might come up
When you run in debugger what is the stack trace on "crash"?
I tried running the debugger but it doesn't even start
-
Well it doesn't look like whatever it is has anything to do with Qt.
I ran this code in Code::Blocks and it worked fine. It does look like it has to do with Qt. But I will do some more digging and what might come up
When you run in debugger what is the stack trace on "crash"?
I tried running the debugger but it doesn't even start
@hbatalha said in std::filesystem crashes my app:
I tried running the debugger but it doesn't even start
What "doesn't even start" --- the program from inside the debugger or the debugger itself?
Anyway, I don't know what "Code::Blocks" might be, or what platform you are on. I only know of using
gdb
withgcc
(e.g. under Linux), or Qt Creator will front-end that for you. Getting the debugger working is an important part of developing. -
@hbatalha said in std::filesystem crashes my app:
I tried running the debugger but it doesn't even start
What "doesn't even start" --- the program from inside the debugger or the debugger itself?
Anyway, I don't know what "Code::Blocks" might be, or what platform you are on. I only know of using
gdb
withgcc
(e.g. under Linux), or Qt Creator will front-end that for you. Getting the debugger working is an important part of developing. -
Hi,
As @JonB suggested what does the debugger tell you ?
By the way, how are you starting your application ? -
@hbatalha said in std::filesystem crashes my app:
QCoreApplication
Are you sure you're using the -std=c++17 or greater on compilation?
Have you read the gcc errata on std::filesystem and its implementation differences on different platforms?std::filesystem was a boost library prior to c++17 and has a list of features that may not be completely supported in different g++ versions on windows.
can you implement your desired behaviour using the Qt filesystem module?
-
I am trying to create a simple program using std::filesystem but my app is always crashing. I am on window using GCC 10.3.0, Qt 6.1.2.
#include <QApplication> #include <fstream> #include <filesystem> // Driver program to test the above function int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); namespace fs = std::filesystem; std::ofstream of("teststxt"); for(auto const& iter : fs::directory_iterator("binf")) { if(fs::is_regular_file(iter)) of << iter.path().filename().string() << std::endl; } of.close(); return a.exec(); }
If I comment out the code that uses std::filesystem it works fines.
@hbatalha said in std::filesystem crashes my app:
If I comment out the code that uses std::filesystem it works fines.
In addition to @Kent-Dorfman's comments. What about if you comment out the 3 lines using anything Qt (
#include
,QCoreApplication
,a.exec()
)? If that still misbehaves you have a fully non-Qt exemplar. -
@hbatalha said in std::filesystem crashes my app:
I don't understand what you mean?
Are you starting it from Qt Creator ? The command line ?
-
@hbatalha said in std::filesystem crashes my app:
I don't understand what you mean?
Are you starting it from Qt Creator ? The command line ?