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.
  • MehrshadM Offline
    MehrshadM Offline
    Mehrshad
    wrote on 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
    • MehrshadM Mehrshad referenced this topic on
    • Christian EhrlicherC Christian Ehrlicher moved this topic from General and Desktop on
    • MehrshadM Mehrshad referenced this topic on
    • cristian-adamC Offline
      cristian-adamC Offline
      cristian-adam
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • MehrshadM Offline
        MehrshadM Offline
        Mehrshad
        wrote on last edited by
        #3

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

        MehrshadM 1 Reply Last reply
        0
        • MehrshadM Mehrshad

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

          MehrshadM Offline
          MehrshadM Offline
          Mehrshad
          wrote on 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?

          cristian-adamC 1 Reply Last reply
          1
          • MehrshadM Mehrshad

            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?

            cristian-adamC Offline
            cristian-adamC Offline
            cristian-adam
            wrote on 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.

            cristian-adamC 1 Reply Last reply
            1
            • cristian-adamC cristian-adam

              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.

              cristian-adamC Offline
              cristian-adamC Offline
              cristian-adam
              wrote on last edited by
              #6

              Which CMake version are you using?

              cristian-adamC 1 Reply Last reply
              0
              • cristian-adamC cristian-adam

                Which CMake version are you using?

                cristian-adamC Offline
                cristian-adamC Offline
                cristian-adam
                wrote on 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.

                MehrshadM 1 Reply Last reply
                1
                • cristian-adamC cristian-adam

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

                  Please use an older version of CMake.

                  MehrshadM Offline
                  MehrshadM Offline
                  Mehrshad
                  wrote on 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
                  • MehrshadM Mehrshad has marked this topic as solved on
                  • MehrshadM Offline
                    MehrshadM Offline
                    Mehrshad
                    wrote on last edited by
                    #9

                    This issue was fixed in Qt Creator 11.0.1.

                    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