utility-boilerplate-qt
utility-boilerplate-qt copied to clipboard
🚀Boilerplate for C++ utility application based on Qt5
English | Русский

What is it?
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.
How to build?
Requirements installation
You need Qt 5.12 at least.
Windows
Install Qt from official site.
Linux
Examples for Ubuntu 20.04, for another version or distributive refer to Qt Wiki.
sudo apt install build-essential qt5-default qttools5-dev-tools
Other systems
See Qt Wiki.
Build
Initialize submodules:
git submodule update --init
In-source build restricted. From source folder do:
cmake -S. -Bbuild
cmake --build build
Example
Directory src/example contains code that show how to create application on this boilerplate.
- Inherit your main window class from
UtilityMainWindowclass 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.cppchangeMainWindowto your class.
Internationalization support
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.
How to assemble new translation?
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>.tsin 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 successfullymessage. If translation can't be load you seeCan't load translation for "<language code>"message. Qt do not offer more debug information for that.
Code style enforcement
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.
Install requirements
Windows
clang-format can be downloaded with LLVM package.
cmake-format installed using pip.
pip install cmakelang pyyaml
Linux
Normally, linux systems has all requirements, except cmake-format.
pip install cmakelang
Using
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
Build in memory leaks detection
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.
Contacts
Rise issues, if you have questions or support request.