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. std::filesystem crashes my app
Forum Updated to NodeBB v4.3 + New Features

std::filesystem crashes my app

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 4 Posters 1.1k Views 3 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.
  • H hbatalha

    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.

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

    @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"?

    H 1 Reply Last reply
    2
    • JonBJ JonB

      @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"?

      H Offline
      H Offline
      hbatalha
      wrote on last edited by
      #3

      @JonB

      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

      JonBJ 1 Reply Last reply
      0
      • H hbatalha

        @JonB

        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

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

        @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 with gcc (e.g. under Linux), or Qt Creator will front-end that for you. Getting the debugger working is an important part of developing.

        H 1 Reply Last reply
        0
        • JonBJ JonB

          @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 with gcc (e.g. under Linux), or Qt Creator will front-end that for you. Getting the debugger working is an important part of developing.

          H Offline
          H Offline
          hbatalha
          wrote on last edited by
          #5

          @JonB

          What "doesn't even start" --- the program from inside the debugger or the debugger itself?

          The debugger

          Anyway, I don't know what "Code::Blocks" might be, or what platform you are on.

          Code::Blocks is a C/C++ IDE and I am on Windows

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #6

            Hi,

            As @JonB suggested what does the debugger tell you ?
            By the way, how are you starting your application ?

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

            H 1 Reply Last reply
            0
            • SGaistS SGaist

              Hi,

              As @JonB suggested what does the debugger tell you ?
              By the way, how are you starting your application ?

              H Offline
              H Offline
              hbatalha
              wrote on last edited by
              #7

              @SGaist

              As @JonB suggested what does the debugger tell you ?

              The debugger doesn't start

              By the way, how are you starting your application ?

              I don't understand what you mean?

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

                @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?

                1 Reply Last reply
                0
                • H hbatalha

                  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.

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

                  @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.

                  1 Reply Last reply
                  0
                  • H hbatalha

                    @SGaist

                    As @JonB suggested what does the debugger tell you ?

                    The debugger doesn't start

                    By the way, how are you starting your application ?

                    I don't understand what you mean?

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

                    @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 ?

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

                    H 1 Reply Last reply
                    0
                    • SGaistS SGaist

                      @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 ?

                      H Offline
                      H Offline
                      hbatalha
                      wrote on last edited by
                      #11

                      @SGaist

                      Are you starting it ? The command line ?

                      from Qt Creator

                      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