Replacing QT Creator with VSCode / neovim
CS106B at Stanford requires the use of QT Creator, an IDE I despise. So I spent a few hours figuring out how to use neovim
with QT Projects. This same guide should also work for VSCode, although I'm not sure how the process differs on Windows – this tutorial is designed for MacOS.
First, install the clangd
extension for the editor of your choice. For me, it was LazyVim (clangd
can be installed as a LazyExtra) but this should also work with the same VSCode extension.
Next, open your QT project in QT Creator, and wait for it to finish indexing using clangd
. After this is done, you can close QT Creator and not touch it again until your next project.
Now there should be a directory /build/Qt_6_7_2_for_macOS-Debug/.qtc_clangd
with a file compile_commands.json
in it. Move this file to the root of your project (next to your .pro
file). Note your QT version may be different.
Now, run qmake -o Makefile YourProjectName.pro
in your root directory. This creates a makefile that can be run with make
. Your output should look something like this:
▲ Developer/qt-demo qmake -o Makefile Demo.pro
Info: creating stash file /Users/eliot/Developer/qt-demo/.qmake.stash
Finally, we can improve some parts of the build process. Running make
builds your app, and you can run it with open YourProjectName.app
. To combine these steps into one command (and to automatically kill previous instances of the app) create a file make.sh
with this content:
pkill YourProjectName
make && open YourProjectName.app
Then make it executable using chmod +x ./make.sh
. Now, you should be able to run your project using ./make.sh
, just like you would in QT Creator.
Bonus Config
For those who want a faster build process, I configured a keymap in neovim
that allows me to build and run my project with space + period
. To do so, I just added the following lines to my keymaps.lua
vim.keymap.set("n", "<leader>.", function()
vim.cmd("!./make.sh")
end, { desc = "Run ./make.sh file (for c++)" })
This should allow you to build fairly quickly! I'm not sure how easy it is to do the same with VSCode, but I'm sure there are some fantastic auto-build extensions available.
Hope this helps!