Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Qt Creator displaying warnings related to C++98
Forum Updated to NodeBB v4.3 + New Features

Qt Creator displaying warnings related to C++98

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
13 Posts 4 Posters 1.3k 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.
  • G Offline
    G Offline
    GregB
    wrote on last edited by
    #1

    I'm running Qt Creator 15.0.1 on Windows, and I'm getting warnings about incompatibilites with C++98. This is appearing as annotations in code editor.

    I've added the following to the .pro file, but it didn't change any behavior

    CONFIG -= c++98
    CONFIG += c++11
    CONFIG += c++17
    

    How can I get the clang code model to ignore C++98 issues?

    1 Reply Last reply
    0
    • Christian EhrlicherC Christian Ehrlicher moved this topic from General and Desktop on
    • aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @GregB You are currently adding both C++11 and C++17 - please choose one of them. If you use an older Qt and therefore qmake version, you might need to replace C++17 with C++1z

      Also, I doubt that CONFIG -= c++98 has any meaning, see https://doc.qt.io/qt-6/qmake-variable-reference.html#config for known variables.

      If you still encounter problems, please share the code you are getting warnings with.

      Regards

      Qt has to stay free or it will die.

      1 Reply Last reply
      0
      • G Offline
        G Offline
        GregB
        wrote on last edited by
        #3

        I changed the .pro file to only contain the c++17. The warnings that I'm getting are within Qt Creator, not from the build process. Some example warnings are below:

        M:\nidb\src\nidb\modulePipeline.cpp:300: warning: 'auto' type specifier is incompatible with C++98
        M:\nidb\src\nidb\modulePipeline.cpp:300: warning: If initialization statements are incompatible with C++ standards before C++17
        M:\nidb\src\nidb\modulePipeline.cpp:1377: warning: Initialization of initializer_list object is incompatible with C++98
        M:\nidb\src\nidb\modulePipeline.cpp:1867: warning: 'auto' type specifier is incompatible with C++98
        M:\nidb\src\nidb\modulePipeline.cpp:1867: warning: If initialization statements are incompatible with C++ standards before C++17
        M:\nidb\src\nidb\modulePipeline.cpp:2188: warning: Universal character name referring to a control character is incompatible with C++98
        
        1 Reply Last reply
        0
        • aha_1980A Offline
          aha_1980A Offline
          aha_1980
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @GregB could you also share the relevant code lines?

          Qt has to stay free or it will die.

          1 Reply Last reply
          0
          • G Offline
            G Offline
            GregB
            wrote on last edited by
            #5

            Line 300

            foreach (int sid, studyids) {
            

            Line 1377

            QStringList bidsflags = { "BIDS_SUBJECTDIR_UID", "BIDS_STUDYDIR_STUDYNUM" };
            

            Line 1867

            foreach (QString group, groups) {
            

            I'm not sure that the code is invalid? This code builds without warnings or error. The only issue is the warnings within Qt Creator generated by clangd within the editor. I recently upgraded my computer and reinstalled Qt Creator, and that's when I started getting the warnings. I was using 15.0.1 before, and 15.0.1 now. I must have had a setting turned off on my previous computer related to clangd, but I don't know what the setting is.

            JonBJ 1 Reply Last reply
            0
            • G GregB

              Line 300

              foreach (int sid, studyids) {
              

              Line 1377

              QStringList bidsflags = { "BIDS_SUBJECTDIR_UID", "BIDS_STUDYDIR_STUDYNUM" };
              

              Line 1867

              foreach (QString group, groups) {
              

              I'm not sure that the code is invalid? This code builds without warnings or error. The only issue is the warnings within Qt Creator generated by clangd within the editor. I recently upgraded my computer and reinstalled Qt Creator, and that's when I started getting the warnings. I was using 15.0.1 before, and 15.0.1 now. I must have had a setting turned off on my previous computer related to clangd, but I don't know what the setting is.

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

              @GregB
              Up to you, but you could change foreach() to for ( : ), and I would guess remove the = in the middle one? Not that you have to, but these are newer constructs and I guess it's moaning about the older ones?

              1 Reply Last reply
              0
              • aha_1980A Offline
                aha_1980A Offline
                aha_1980
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @GregB Thanks. Looking at the foreach source code there is indeed a line for (auto name = QtPrivate::qMakeForeachContainer(container); name.i != name.e; ++name.i) which is valid C++11 and higher code.

                So I think for some reason the code model does not pick up the C++17 specifier. Can you try a minimal "Hello World" style example?

                @JonB Be careful with such suggestions. Changing foreach() to range-based for requires a studies with diploma exam ;)

                Regards

                Qt has to stay free or it will die.

                JonBJ 1 Reply Last reply
                0
                • aha_1980A aha_1980

                  @GregB Thanks. Looking at the foreach source code there is indeed a line for (auto name = QtPrivate::qMakeForeachContainer(container); name.i != name.e; ++name.i) which is valid C++11 and higher code.

                  So I think for some reason the code model does not pick up the C++17 specifier. Can you try a minimal "Hello World" style example?

                  @JonB Be careful with such suggestions. Changing foreach() to range-based for requires a studies with diploma exam ;)

                  Regards

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

                  @aha_1980 said in Qt Creator displaying warnings related to C++98:

                  @JonB Be careful with such suggestions. Changing foreach() to range-based for requires a studies with diploma exam ;)

                  If you say so! I only know that I use for instead of foreach (at least in similar cases to what the OP shows above, an int and a QString and their lists) and never had any issues?

                  1 Reply Last reply
                  0
                  • aha_1980A Offline
                    aha_1980A Offline
                    aha_1980
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @JonB: You think you don't have any issues before you read the post Goodbye Q_FOREACH! I mentioned.

                    Regards

                    Qt has to stay free or it will die.

                    JonBJ 1 Reply Last reply
                    0
                    • aha_1980A aha_1980

                      @JonB: You think you don't have any issues before you read the post Goodbye Q_FOREACH! I mentioned.

                      Regards

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

                      @aha_1980
                      But just to round off, I thought there are no issues for the specific int-in-list and QString-in-QStringList OP's cases as shown, or are there?

                      1 Reply Last reply
                      0
                      • aha_1980A Offline
                        aha_1980A Offline
                        aha_1980
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        @JonB: not for the int and the QString , but probably for the corresponding lists. But for the details, you will have to read the mentioned post.

                        Qt has to stay free or it will die.

                        1 Reply Last reply
                        1
                        • G Offline
                          G Offline
                          GregB
                          wrote on last edited by
                          #12

                          Thanks for the comments. So I don't think there's anything wrong with the code itself. It seems to be a configuration with Qt Creator and clangd that is ignoring the c++17 specification in the .pro file.

                          I found a previous post about this issue, and how they fixed it: https://forum.qt.io/topic/109856/incompatible-with-c-98-warnings-since-qt-creater-update/3

                          But that post is 5 years old, and none of the options they used to fix the issue exist in in the current Qt Creator.

                          1 Reply Last reply
                          0
                          • F Offline
                            F Offline
                            f222
                            wrote last edited by
                            #13

                            I might be digging up the post but I encountered the same issue because I had spaces in my compiler flags.

                            I am using clang-cl and in my .pro file I added includes using imsvc to avoid warning on those files like so:

                            QMAKE_CXXFLAGS += /imsvc\"C:/path with spaces /to/include/folder\"

                            Using \ before the quotes and / as path delimiter allows the code to compile as expected but it doesn't prevent the code model from being broken.

                            If I go to Tools->Debug Qt Creator -> Inspect C++ code model , under Project Parts tab in the General tab and look at the compiler flags you can see that it will split the path on the spaces and consider the parts of the path as separate flags:

                            83e25b37-b4a8-4039-b813-87b596b1db2a-image.png

                            (Example shown on Qt5 but it's the same with Qt 6)

                            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