Skip to main content
  1. Blogs/

Cheatsheet for Qt Build and Development

·213 words·1 min· loading · loading ·
Author
Yuhao Han
A traveler in the Realm of Maths

Build System
#

Qt projects can be build with many different build softwares. Among themqmake is the official build system and one of the most popular. This is a quick introduction to qmake.

qmake reads a project file <project-name>.pro, which defines the project and list its source files, headers, and dependencies. A dummy example of a .pro file is this

# add qt widgets module to dependencies
QT += widgets

CONFIG += c++17 console
CONFIG -= app_bundle

SOURCES += \
    main.cpp \
    window.cpp

HEADERS += \
    window.h

FORMS += \
    window.ui

It is recommended to build the project in the build directory

mkdir build
cd build 
qmake ../<project-name>.pro # qmake generated the Makefile
make # make clean to clean the build directory

QT projects on Neovim, Clangd and LSP
#

For the LSP server clangd to successfuly parse the project, it needs to know the location of the header files and the compiler flags. This can be achieved using a JSON compilation database, which records the headers and dependencies of the source files.

The easiest way to generate a JSON compilation database is to use bear. After running qmake, run the following command in the build directory to generate the compile_commands.json file.

bear -- make

And now the LSP server shall work correctly.