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. filesystem in C++17 and Q_OBJECT conflicts
Forum Updated to NodeBB v4.3 + New Features

filesystem in C++17 and Q_OBJECT conflicts

Scheduled Pinned Locked Moved Solved General and Desktop
18 Posts 9 Posters 2.5k Views 1 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.
  • J Offline
    J Offline
    jronald
    wrote on 23 Nov 2021, 09:31 last edited by jronald
    #1

    Env

    Qt 6.2.1
    Linux

    Sample

    CMakeLists.txt

    ...
    set(CMAKE_CXX_STANDARD 17)
    set(CMAKE_CXX_STANDARD_REQUIRED ON)
    ...
    

    C++ code

    #include <filesystem>
    #include <QApplication>
    
    class MyApp : public QApplication
    {
        Q_OBJECT
        ...
    }
    

    Error

    usr/include/c++/11.1.0/bits/fs_fwd.:39:1: error: Parse error at "std"
    

    More Info
    If remove #include <filesystem>, it builds successfully.


    EDIT
    If #include <filesystem> after #include <QApplication>, the problem disappers, why?

    #include <QApplication>
    #include <filesystem>
    
    J R 2 Replies Last reply 23 Nov 2021, 10:38
    0
    • V Offline
      V Offline
      VRonin
      wrote on 23 Nov 2021, 13:35 last edited by
      #10

      This is a bug in MOC: https://bugreports.qt.io/browse/QTBUG-73263 what they suggest is to reorder the includes as you already figured out

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      4
      • J jronald
        23 Nov 2021, 09:31

        Env

        Qt 6.2.1
        Linux

        Sample

        CMakeLists.txt

        ...
        set(CMAKE_CXX_STANDARD 17)
        set(CMAKE_CXX_STANDARD_REQUIRED ON)
        ...
        

        C++ code

        #include <filesystem>
        #include <QApplication>
        
        class MyApp : public QApplication
        {
            Q_OBJECT
            ...
        }
        

        Error

        usr/include/c++/11.1.0/bits/fs_fwd.:39:1: error: Parse error at "std"
        

        More Info
        If remove #include <filesystem>, it builds successfully.


        EDIT
        If #include <filesystem> after #include <QApplication>, the problem disappers, why?

        #include <QApplication>
        #include <filesystem>
        
        J Offline
        J Offline
        JonB
        wrote on 23 Nov 2021, 10:38 last edited by JonB
        #2

        @jronald said in filesystem in C++17 and Q_OBJECT conflicts:

        Parse error at "std"

        Purely at a guess <filesystem> needs <std> stuff to be included first? <QApplication> includes that so makes it work if included before <filesystem>? Or something along those lines. Does not sound like that should be so, but it's what you describe as behaviour....

        usr/include/c++/11.1.0/bits/fs_fwd.:39:1: error: Parse error at "std"
        

        I am surprised that path does not start with /usr? I am no expert, but should a C++17 be including a c++/11.1.0 header file, is that a possible issue?

        Actually your error is reported at https://stackoverflow.com/questions/69407237/qt-moc-errorusr-include-c-10-bits-fs-fwd-39-parse-error-at-std one month ago. Not sure what the "solution" is, but that's the issue....

        1 Reply Last reply
        2
        • J Offline
          J Offline
          jronald
          wrote on 23 Nov 2021, 11:38 last edited by
          #3

          @JonB
          tried

          #include <std>
          #include <filesystem>
          #include <QApplication>
          

          But <std> doesn't exist.

          J 1 Reply Last reply 23 Nov 2021, 12:31
          0
          • J jronald
            23 Nov 2021, 09:31

            Env

            Qt 6.2.1
            Linux

            Sample

            CMakeLists.txt

            ...
            set(CMAKE_CXX_STANDARD 17)
            set(CMAKE_CXX_STANDARD_REQUIRED ON)
            ...
            

            C++ code

            #include <filesystem>
            #include <QApplication>
            
            class MyApp : public QApplication
            {
                Q_OBJECT
                ...
            }
            

            Error

            usr/include/c++/11.1.0/bits/fs_fwd.:39:1: error: Parse error at "std"
            

            More Info
            If remove #include <filesystem>, it builds successfully.


            EDIT
            If #include <filesystem> after #include <QApplication>, the problem disappers, why?

            #include <QApplication>
            #include <filesystem>
            
            R Offline
            R Offline
            raven-worx
            Moderators
            wrote on 23 Nov 2021, 11:48 last edited by
            #4

            @jronald
            what compiler (version) are you using?

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            J 1 Reply Last reply 23 Nov 2021, 12:55
            0
            • J jronald
              23 Nov 2021, 11:38

              @JonB
              tried

              #include <std>
              #include <filesystem>
              #include <QApplication>
              

              But <std> doesn't exist.

              J Offline
              J Offline
              JonB
              wrote on 23 Nov 2021, 12:31 last edited by
              #5

              @jronald said in filesystem in C++17 and Q_OBJECT conflicts:

              But <std> doesn't exist.

              I didn't say it did, I was talking conceptually. In any case since you know

              #include <QApplication>
              #include <filesystem>
              

              works, use that. Else you'll have to follow the discussion in that stackoverflow post.

              1 Reply Last reply
              1
              • D Offline
                D Offline
                django.Reinhard
                wrote on 23 Nov 2021, 12:36 last edited by
                #6

                Hi,

                I use filesystem from stdlib without trouble. And without using QApplication in same file.

                I suspect that errormessage from first post depends on files included before "filesystem" (not mentioned in your post).

                The given line from error message looks like:

                namespace std _GLIBCXX_VISIBILITY(default)
                

                So may be 'namespace' has been declared as a macro or that GLib-Token does not exists. I can't imagine of other errors.

                The include-file "std" (without extension) is a boost include file.

                so may be, something is mixed without intention?

                J 1 Reply Last reply 23 Nov 2021, 13:00
                0
                • R raven-worx
                  23 Nov 2021, 11:48

                  @jronald
                  what compiler (version) are you using?

                  J Offline
                  J Offline
                  jronald
                  wrote on 23 Nov 2021, 12:55 last edited by
                  #7

                  @raven-worx said in filesystem in C++17 and Q_OBJECT conflicts:

                  @jronald
                  what compiler (version) are you using?

                  g++ 11.1.0

                  1 Reply Last reply
                  0
                  • D django.Reinhard
                    23 Nov 2021, 12:36

                    Hi,

                    I use filesystem from stdlib without trouble. And without using QApplication in same file.

                    I suspect that errormessage from first post depends on files included before "filesystem" (not mentioned in your post).

                    The given line from error message looks like:

                    namespace std _GLIBCXX_VISIBILITY(default)
                    

                    So may be 'namespace' has been declared as a macro or that GLib-Token does not exists. I can't imagine of other errors.

                    The include-file "std" (without extension) is a boost include file.

                    so may be, something is mixed without intention?

                    J Offline
                    J Offline
                    jronald
                    wrote on 23 Nov 2021, 13:00 last edited by
                    #8

                    @django-Reinhard said in filesystem in C++17 and Q_OBJECT conflicts:

                    Hi,

                    I use filesystem from stdlib without trouble. And without using QApplication in same file.

                    I suspect that errormessage from first post depends on files included before "filesystem" (not mentioned in your post).

                    The given line from error message looks like:

                    namespace std _GLIBCXX_VISIBILITY(default)
                    

                    So may be 'namespace' has been declared as a macro or that GLib-Token does not exists. I can't imagine of other errors.

                    The include-file "std" (without extension) is a boost include file.

                    so may be, something is mixed without intention?

                    To reproduce the problem, two conditions must be meeted:

                    • #include <filesystem> before #include <QApplication>
                    • MyApp must inlcude Q_OBJECT
                    J B 2 Replies Last reply 23 Nov 2021, 13:05
                    0
                    • J jronald
                      23 Nov 2021, 13:00

                      @django-Reinhard said in filesystem in C++17 and Q_OBJECT conflicts:

                      Hi,

                      I use filesystem from stdlib without trouble. And without using QApplication in same file.

                      I suspect that errormessage from first post depends on files included before "filesystem" (not mentioned in your post).

                      The given line from error message looks like:

                      namespace std _GLIBCXX_VISIBILITY(default)
                      

                      So may be 'namespace' has been declared as a macro or that GLib-Token does not exists. I can't imagine of other errors.

                      The include-file "std" (without extension) is a boost include file.

                      so may be, something is mixed without intention?

                      To reproduce the problem, two conditions must be meeted:

                      • #include <filesystem> before #include <QApplication>
                      • MyApp must inlcude Q_OBJECT
                      J Offline
                      J Offline
                      JonB
                      wrote on 23 Nov 2021, 13:05 last edited by JonB
                      #9

                      @jronald
                      You can keep asking questions and have others make guesses if you wish, but I have already given you the stackoverflow post which shows this error and indicates where the problem lies (i.e. in the toolchain).

                      As it states there, the error comes from moc. And that is only invoked if you have a Q_OBJECT macro present. It also tells you the problem lies in cmake (which is what you are using), but not in qmake. Hence your findings.

                      I'll leave you to it now.

                      1 Reply Last reply
                      2
                      • V Offline
                        V Offline
                        VRonin
                        wrote on 23 Nov 2021, 13:35 last edited by
                        #10

                        This is a bug in MOC: https://bugreports.qt.io/browse/QTBUG-73263 what they suggest is to reorder the includes as you already figured out

                        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                        ~Napoleon Bonaparte

                        On a crusade to banish setIndexWidget() from the holy land of Qt

                        1 Reply Last reply
                        4
                        • J jronald
                          23 Nov 2021, 13:00

                          @django-Reinhard said in filesystem in C++17 and Q_OBJECT conflicts:

                          Hi,

                          I use filesystem from stdlib without trouble. And without using QApplication in same file.

                          I suspect that errormessage from first post depends on files included before "filesystem" (not mentioned in your post).

                          The given line from error message looks like:

                          namespace std _GLIBCXX_VISIBILITY(default)
                          

                          So may be 'namespace' has been declared as a macro or that GLib-Token does not exists. I can't imagine of other errors.

                          The include-file "std" (without extension) is a boost include file.

                          so may be, something is mixed without intention?

                          To reproduce the problem, two conditions must be meeted:

                          • #include <filesystem> before #include <QApplication>
                          • MyApp must inlcude Q_OBJECT
                          B Offline
                          B Offline
                          britsfp
                          wrote on 26 Nov 2021, 10:26 last edited by
                          #11

                          @jronald
                          Hi, Here is something else: there is no <filesystem> file on my installation? How do I get this?

                          Regards
                          Frik Brits.

                          jsulmJ 1 Reply Last reply 26 Nov 2021, 10:28
                          0
                          • B britsfp
                            26 Nov 2021, 10:26

                            @jronald
                            Hi, Here is something else: there is no <filesystem> file on my installation? How do I get this?

                            Regards
                            Frik Brits.

                            jsulmJ Offline
                            jsulmJ Offline
                            jsulm
                            Lifetime Qt Champion
                            wrote on 26 Nov 2021, 10:28 last edited by
                            #12

                            @britsfp What compiler do you have?
                            You need C++17 capable compiler and also C++17 needs to be activated in pro file when using g++/MinGW (CONFIG += c++17).

                            https://forum.qt.io/topic/113070/qt-code-of-conduct

                            B 1 Reply Last reply 26 Nov 2021, 11:35
                            0
                            • jsulmJ jsulm
                              26 Nov 2021, 10:28

                              @britsfp What compiler do you have?
                              You need C++17 capable compiler and also C++17 needs to be activated in pro file when using g++/MinGW (CONFIG += c++17).

                              B Offline
                              B Offline
                              britsfp
                              wrote on 26 Nov 2021, 11:35 last edited by
                              #13

                              @jsulm I am using Qt 6.2.1. In the Kits's Compile tab It has gcc 7 and gcc 10 for C programs.
                              For C++ compiler it has g++ 7 and g++ 10

                              I could always change the soft link in /usr/bin ??

                              jsulmJ 1 Reply Last reply 26 Nov 2021, 11:41
                              0
                              • B britsfp
                                26 Nov 2021, 11:35

                                @jsulm I am using Qt 6.2.1. In the Kits's Compile tab It has gcc 7 and gcc 10 for C programs.
                                For C++ compiler it has g++ 7 and g++ 10

                                I could always change the soft link in /usr/bin ??

                                jsulmJ Offline
                                jsulmJ Offline
                                jsulm
                                Lifetime Qt Champion
                                wrote on 26 Nov 2021, 11:41 last edited by
                                #14

                                @britsfp said in filesystem in C++17 and Q_OBJECT conflicts:

                                I could always change the soft link in /usr/bin ??

                                There is no need for such hacks.
                                Simply define the compiler in your Kit in QtCreator.

                                https://forum.qt.io/topic/113070/qt-code-of-conduct

                                B 1 Reply Last reply 26 Nov 2021, 11:49
                                0
                                • jsulmJ jsulm
                                  26 Nov 2021, 11:41

                                  @britsfp said in filesystem in C++17 and Q_OBJECT conflicts:

                                  I could always change the soft link in /usr/bin ??

                                  There is no need for such hacks.
                                  Simply define the compiler in your Kit in QtCreator.

                                  B Offline
                                  B Offline
                                  britsfp
                                  wrote on 26 Nov 2021, 11:49 last edited by
                                  #15

                                  @jsulm
                                  Ok So must both C and C++ be version 10?, I supose so ? - and what is this #include <filesystem> error I get from the qfile.h header?

                                  jsulmJ JoeCFDJ 2 Replies Last reply 26 Nov 2021, 11:59
                                  0
                                  • B britsfp
                                    26 Nov 2021, 11:49

                                    @jsulm
                                    Ok So must both C and C++ be version 10?, I supose so ? - and what is this #include <filesystem> error I get from the qfile.h header?

                                    jsulmJ Offline
                                    jsulmJ Offline
                                    jsulm
                                    Lifetime Qt Champion
                                    wrote on 26 Nov 2021, 11:59 last edited by
                                    #16

                                    @britsfp C doesn't matter most of the time, unless you want to compile C code.
                                    But usually should point to same compiler version.

                                    "and what is this #include <filesystem> error I get from the qfile.h header?" - as I said already: you need a compiler which supports C++17 standard and you need to enable this standard in your pro file.
                                    https://en.cppreference.com/w/cpp/filesystem

                                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                                    1 Reply Last reply
                                    0
                                    • B britsfp
                                      26 Nov 2021, 11:49

                                      @jsulm
                                      Ok So must both C and C++ be version 10?, I supose so ? - and what is this #include <filesystem> error I get from the qfile.h header?

                                      JoeCFDJ Offline
                                      JoeCFDJ Offline
                                      JoeCFD
                                      wrote on 26 Nov 2021, 16:36 last edited by
                                      #17

                                      @britsfp g++ 7 does not support <filesystem>. If you can, set both C and C++ to 11 which supports C++20

                                      1 Reply Last reply
                                      0
                                      • C Offline
                                        C Offline
                                        chavsur
                                        wrote on 28 Nov 2021, 17:38 last edited by chavsur
                                        #18

                                        i have also faced same thing while compilation. .

                                        1 Reply Last reply
                                        0

                                        1/18

                                        23 Nov 2021, 09:31

                                        • Login

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