English | Русский
Template for creating simple cross-platform application with GUI based on Qt.
You can go straight to developing widget contained target functionality.
Features:
- Ready-to-go template.
- Cross-platform. Can be build for Windows, Linux, any OS that Qt support.
- Minimal architecture and directory structure, to keep coupling low.
- Settings system, with OS independent storage and behavior.
- Test suites and code coverage already setup.
- Code style enforcing tooling.
- Internationalization support.
- Build in memory leaks detection.
- No Boost.
- Cmake as build system.
- Basic CI, based on GitHub Actions.
You need Qt 5.12 at least.
Install Qt from official site.
Examples for Ubuntu 20.04, for another version or distributive refer to Qt Wiki.
sudo apt install build-essential qt5-default qttools5-dev-tools
See Qt Wiki.
Initialize submodules:
git submodule update --init
In-source build restricted. From source folder do:
cmake -S. -Bbuild
cmake --build build
Directory src/example
contains code that show how to create application on this boilerplate.
- Inherit your main window class from
UtilityMainWindow
class instead ofQMainWindow
. - Initialize UI in constructor by Qt documentation, add you widget and so on.
- Override getExtensions(), getFileReadMode(), getFileWriteMode() to specified file types and read-write modes.
- Override loadFile(fileName) and saveFile(filename) implementing read and write file from disc. See example for basic variant.
- Implement isDocumentModified() and clearDocument() this let window to keep track of document state.
- Delegate methods cut(), copy() and paste() to your widget.
- In
main.cpp
changeMainWindow
to your class.
This boilerplate code include Qt internationalization support.
You need to create application translation files to make it work.
Take a note, for now module utility_boilerplate_qt5
support only 2 languages:
- English - in-built to sources
- Russian
Pull requests with another language are welcome.
ru_RU as example, use your language code.
-
Collect all strings inside
tr()
to TS file usinglupdate
.lupdate *.cpp -ts i18n/ru/app_ru.ts
-
Open it in translation tool and translate.
linguist i18n/ru/app_ru.ts
-
Qt can load only one translation file at ones, so you need to collect a complete translation file with
lconvert
. Search for Qtqtbase_<language code>.ts
in distribution package or repository and place it in toi18n/<language code>
folder. Next merge TS files to one usinglconvert
.cd i18n/ lconvert -i ru/*.ts ../../utility_boilerplate_qt5/i18n/ru/*.ts -o ru/appcomp_ru.ts
-
At last convert TS file to QM file using
lrelease
. Build system automatically copy all QM files to appropriate location, where binaries can find it.lrelease ru/appcomp_ru.ts ru/appcomp_ru.qm
-
To check that translation load correctly run application from command line and look for
Translation for "<language code>" load successfully
message. If translation can't be load you seeCan't load translation for "<language code>"
message. Qt do not offer more debug information for that.
Project offer code style enforcement via clang-format and cmake-format. IDEA styles included.
Style workflow failed if any project file has bad formatting.
Format enforcing ignored if requirements not installed.
clang-format
can be downloaded with LLVM package.
cmake-format
installed using pip
.
pip install cmakelang pyyaml
Normally, linux systems has all requirements, except cmake-format
.
pip install cmakelang
See Format.cmake documentation for details.
Check format of all project files.
cmake --build build --target check-format
Fix all files in project.
cmake --build build --target fix-format
Boilerplate have memory leaks detection based debug_new technics implemented by NVWA library.
Can be enabled on Linux and Mac by adding -DNVWA
on build.
Disabled on Windows due poor compatibility.
Rise issues, if you have questions or support request.