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. When using CMake to generate a Visual Studio 2019 project, the project can compile but fails to locate definitions

When using CMake to generate a Visual Studio 2019 project, the project can compile but fails to locate definitions

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
4 Posts 2 Posters 95 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.
  • L Offline
    L Offline
    lyvvvv
    wrote 22 days ago last edited by
    #1

    When using CMake to generate a Visual Studio 2019 project, the project can compile but fails to locate definitions

    Qt version: qt6.2.2
    VS version: vs2019

    When creating a CMake project using QtCreator, the project compiles successfully, and pressing F2 can locate the definition of QWidget.
    After converting the project to an sln solution using cmake-gui, the project still compiles successfully, but pressing F12 cannot find the definition of QWidget.

    I tried adding the following to CMakeLists.txt:

    include_directories("E:/qt6/6.2.2msvc2019_64/include")  
    target_include_directories(untitled PRIVATE "E:/qt6/6.2.2msvc2019_64/include")  
    

    Neither worked.

    The issue is only resolved by manually adding the Qt path in the sln solution, but once modifying CMakeLists.txt requires editing the sln solution again, which is cumbersome.

    Is there a way to modify CMakeLists.txt so that the definitions of Qt classes can be found?

    J 1 Reply Last reply 22 days ago
    0
    • C Christian Ehrlicher moved this topic from General and Desktop 22 days ago
    • L lyvvvv
      22 days ago

      When using CMake to generate a Visual Studio 2019 project, the project can compile but fails to locate definitions

      Qt version: qt6.2.2
      VS version: vs2019

      When creating a CMake project using QtCreator, the project compiles successfully, and pressing F2 can locate the definition of QWidget.
      After converting the project to an sln solution using cmake-gui, the project still compiles successfully, but pressing F12 cannot find the definition of QWidget.

      I tried adding the following to CMakeLists.txt:

      include_directories("E:/qt6/6.2.2msvc2019_64/include")  
      target_include_directories(untitled PRIVATE "E:/qt6/6.2.2msvc2019_64/include")  
      

      Neither worked.

      The issue is only resolved by manually adding the Qt path in the sln solution, but once modifying CMakeLists.txt requires editing the sln solution again, which is cumbersome.

      Is there a way to modify CMakeLists.txt so that the definitions of Qt classes can be found?

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote 22 days ago last edited by
      #2

      @lyvvvv If symbols are not find then it means that a library is not found while linking.
      Do you have this line in your CMakeLists.txt:

      find_package(Qt6 REQUIRED COMPONENTS Widgets)
      

      ?

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

      1 Reply Last reply
      0
      • L Offline
        L Offline
        lyvvvv
        wrote 21 days ago last edited by
        #3

        This line of code has been added.

        Without it, the project cannot be compiled.

        J 1 Reply Last reply 21 days ago
        0
        • L lyvvvv
          21 days ago

          This line of code has been added.

          Without it, the project cannot be compiled.

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote 21 days ago last edited by
          #4

          @lyvvvv As far as I know Visual Studio supports CMake - why not using it directly instead of sln?

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

          1 Reply Last reply
          0

          4/4

          28 Apr 2025, 11:56

          • Login

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