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. Clang Code Model doesn't work when using CMake
QtWS25 Last Chance

Clang Code Model doesn't work when using CMake

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
qt-creatorclangcmakeqmake
9 Posts 2 Posters 1.6k Views
  • 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.
  • M Offline
    M Offline
    Mehrshad
    wrote on 30 Jul 2023, 08:03 last edited by
    #1

    Hi.
    I recently upgraded from Qt 6.4 to 6.5 and Qt Creator 10.0.2 to 11.0.0. One strange thing I noticed was that features provided by the Clang Code Model plugin were no longer working properly and I had loads of errors in front of me. Here's a screenshot:

    Screen Shot 1402-05-08 at 11.15.58 1.jpg

    Strangely though, there wasn't any such error when using qmake as the build system. I understand this specific problem and the error related to Clang Code
    Model had been discussed before, but hasn't it been solved in 2023? And for what reason does the problem persist only when using CMake? Is there anything I need to modify?

    Further note: First, you need to know in both cases programs are being built and run perfectly.
    Second, I do know disabling Clang Code Model suppresses the errors, but I would lose countless others features as mentioned here. Hence, I don't consider this a solution. Furthermore, as mentioned here again, I could use the built-in code model via clangd, by going through Edit > Preferences > C++ > clangd, but I don't see any such option and thus believe the documentation is outdated.

    1 Reply Last reply
    1
    • M Mehrshad referenced this topic on 30 Jul 2023, 08:16
    • C Christian Ehrlicher moved this topic from General and Desktop on 30 Jul 2023, 08:25
    • M Mehrshad referenced this topic on 30 Jul 2023, 08:27
    • C Online
      C Online
      cristian-adam
      wrote on 31 Jul 2023, 15:44 last edited by
      #2

      See https://bugreports.qt.io/browse/QTCREATORBUG-29450 for a similar report.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Mehrshad
        wrote on 31 Jul 2023, 20:54 last edited by
        #3

        Just to be more complete, I’m on macOS 12.6.8.

        M 1 Reply Last reply 1 Aug 2023, 08:02
        0
        • M Mehrshad
          31 Jul 2023, 20:54

          Just to be more complete, I’m on macOS 12.6.8.

          M Offline
          M Offline
          Mehrshad
          wrote on 1 Aug 2023, 08:02 last edited by
          #4

          One think I don't understand is the dependence of this issue on the build system used. Why there aren't any errors when using qmake? Does the Clang Code Model plugin rely on CMake or qmake for its functionality?

          C 1 Reply Last reply 1 Aug 2023, 09:24
          1
          • M Mehrshad
            1 Aug 2023, 08:02

            One think I don't understand is the dependence of this issue on the build system used. Why there aren't any errors when using qmake? Does the Clang Code Model plugin rely on CMake or qmake for its functionality?

            C Online
            C Online
            cristian-adam
            wrote on 1 Aug 2023, 09:24 last edited by
            #5

            As I mentioned in the bugreport, the Clang Code Model plugin is using clangd which gets the project information via a compile_commands.json file.

            Qt Creator writes it under <build-dir>/.qtc_clangd/compile_commands.json.

            You can compare the compile_commands.json file resulted from qmake and the one resulted from CMake and see what's going wrong with the CMake one.

            You can enable logging for Qt Creator by setting the environment variable QT_LOGGING_RULES=qtc.clang*=true before starting Qt Creator.

            You might get some hints why the CMake project is not working as expected.

            C 1 Reply Last reply 1 Aug 2023, 13:39
            1
            • C cristian-adam
              1 Aug 2023, 09:24

              As I mentioned in the bugreport, the Clang Code Model plugin is using clangd which gets the project information via a compile_commands.json file.

              Qt Creator writes it under <build-dir>/.qtc_clangd/compile_commands.json.

              You can compare the compile_commands.json file resulted from qmake and the one resulted from CMake and see what's going wrong with the CMake one.

              You can enable logging for Qt Creator by setting the environment variable QT_LOGGING_RULES=qtc.clang*=true before starting Qt Creator.

              You might get some hints why the CMake project is not working as expected.

              C Online
              C Online
              cristian-adam
              wrote on 1 Aug 2023, 13:39 last edited by
              #6

              Which CMake version are you using?

              C 1 Reply Last reply 1 Aug 2023, 14:14
              0
              • C cristian-adam
                1 Aug 2023, 13:39

                Which CMake version are you using?

                C Online
                C Online
                cristian-adam
                wrote on 1 Aug 2023, 14:14 last edited by
                #7

                We found that that using CMake version 3.27.0 or 3.27.1 causes issues.

                Please use an older version of CMake.

                M 1 Reply Last reply 1 Aug 2023, 16:30
                1
                • C cristian-adam
                  1 Aug 2023, 14:14

                  We found that that using CMake version 3.27.0 or 3.27.1 causes issues.

                  Please use an older version of CMake.

                  M Offline
                  M Offline
                  Mehrshad
                  wrote on 1 Aug 2023, 16:30 last edited by
                  #8

                  Indeed. I switched to the CMake version provided by Qt, deleted the build directory, re-ran "Build > Run CMake" and all was fixed.
                  Thanks everyone.

                  1 Reply Last reply
                  1
                  • M Mehrshad has marked this topic as solved on 1 Aug 2023, 16:30
                  • M Offline
                    M Offline
                    Mehrshad
                    wrote on 28 Feb 2024, 15:34 last edited by
                    #9

                    This issue was fixed in Qt Creator 11.0.1.

                    1 Reply Last reply
                    0

                    9/9

                    28 Feb 2024, 15:34

                    • Login

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