A minimal template to generate Qt C++ applications in vscode, using CMake to compile and present a user widget in a window.
This code template uses the "single inheritance" method described in the Qt Designer documentation from the Qt Group.
The single inheritance method requires that the developer create a UI class that has the same base class as the UI form that the user has created with Qt Designer. This user class essentially serves as a proxy for the automatically generated class designed in Qt Designer, implementing all of its essential business logic. See the Qt Designer documentation for details.
Note that, as shown in the example in this repo, after generating the form classes
once from the build, the headers should be available on the search path, so after
creating them the first time, content assist should be available for their members.
We've discovered however, that the auto-generated class header still must be
referenced at least once in the codebase before it is generated. These header
names are easy to predict though. For example if the name of the form class you
created in Qt Designer is Widget
, the corresponding header generated during
the build phase will be ui_widget.h
.
The autogenerated files are located in the folder build/${PROJECT_NAME}_autogen/include
The ".vscode" folder contains three files that provide convenient integration between VSCode and Qt for C++ development:
- extensions.json
- tasks.json
The extensions.json
file provides a list of recommended extensions that will
help you to develop C++ code for Qt in VSCode:
- basic C++ development extensions to provide syntax highlighting and content assist, and build integration:
- ms-vscode.cpptools
- ms-vscode.cmake-tools
- twxs.cmake
- donjayamanne.githistory
- formulahendry.code-runner: allows the user to right click on Qt ".ui" and ".qrc" files, and automatically bring up Qt Designer from within vscode
- spencerwmiles.vscode-task-buttons: allows the user to create a button in the bottom task bar called "Qt Designer", which is linked to a regular task (in tasks.json) to start Qt Designer without an existing ui or qrc file, so that the user can create a new one