tonka3000 / vscode-qt-tools

Qt tools extension for Visual Studio Code
MIT License
41 stars 10 forks source link

[question] What is the mechanism of `"qttools.searchMode": "cmake"`? #69

Open hwhsu1231 opened 2 years ago

hwhsu1231 commented 2 years ago

Excuse me, I want to verify the mechanism of "qttools.searchMode": "cmake". Here is my opinion:

  1. If we use find_package(Qt6) or find_package(Qt5) in CMakeLists.txt, then the Cache Variable Qt6_DIR or Qt5_DIR will be written in the CMakeCache.txt after configuring the CMake project.

  2. Then qttools will use this Qt6_DIR or Qt5_DIR to locate some tools such as designer.exe relatively.

Am I correct?

tonka3000 commented 2 years ago

Correct

hwhsu1231 commented 2 years ago

@tonka3000, here is a problem I encountered. What if the value of QtX_DIR is not the traditional location?

Recently, I tried to find_package the Qt installed by Conan from conan-center-index. The Conan generator I used is CMakeDeps or cmake_find_package_multi. The mechanism of these generators is to generate some *-config.cmake files inside the build directory, and then we can use find_package to load the configurations.

We can see that the Qt6_DIR after configuring is the following (becuase the Qt6Config.cmake is actually in this directory):

D:\TEST-qt-cmake_find_package\build\conan\

However, the directory of binary packages of Qt installed by Conan is here:

C:\.conan\b9fb5546\1\

Therefore, the bottom status bar shows "Qt not found". Do you have any idea to deal with this situation?

Example Code

TEST-qt-cmake_find_package.zip

Screenshots

image

hwhsu1231 commented 2 years ago

I think the best solution (for now) is to use qttools.extraSearchDirectories to add the bin directory of Qt Kits manually. For example:

{
  "qttools.extraSearchDirectories": [
    "C:\\Qt\\6.2.0\\msvc2019_64\\bin",
  ]
}

In other words, I have to install Qt by Official Installer, anyway.

As for Qt installed by Conan, I don't need and had better not to add qt:tools=True option in conanfile.txt because it seems that there are only Binary Packages of Qt with default option of qt:tools=False in conan-center-index. That is, it will take a lot of time to compile the Source Package for the first time if I add qt:tools=True option in conanfile.txt.