Qt6/Example-Guideline: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
(Replaced content with "Category:Developing Qt::Examples This page is obsolete and deprecated. For Qt 6 information, see Qt Examples Guidelines")
Tags: Replaced Visual edit
 
(70 intermediate revisions by 12 users not shown)
Line 1: Line 1:
''When creating or updating Qt examples, developer should consider the best practises and guidelines listed in this document.''
[[Category:Developing Qt::Examples]]
 
This page is obsolete and deprecated. For Qt 6 information, see [[Qt Examples Guidelines]]
==Evaluate if the example is meaningful or should it be removed/merged==
'''MANDATORY'''
 
*Check if there are similar examples for the same topic and consider if both are really needed or should the other one be merged with the other.
*Check also documentation on the topic and if that includes inline code snippet that would be adequate instead of complete example.
 
==No C++ or qml warnings==
'''MANDATORY'''
 
*Example's C++ code should be by minimum compiled with the same compiler warning flags as Qt.
*Use qmllint for qml code: https://doc-snapshots.qt.io/qt6-dev/qtquick-tool-qmllint.html
*Enable compiler warnings and check if the reported issues are fixable with meaningful effort.
 
<br>
'''RECOMMENDED'''
<br>
Consider also the compilation with the more strict warning flags and fix the found issues.
<br>
GCC
 
*Use -Wall and consider -Wextra parameter: https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
 
Clang
 
*Use -Weverything compiler parameter: https://clang.llvm.org/docs/UsersManual.html#diagnostics-enable-everything
 
Visual Studio
 
*Use /Wall compiler parameter: https://docs.microsoft.com/en-us/cpp/build/reference/compiler-option-warning-level
 
==Qt6 best practises and changes==
'''MANDATORY'''
 
*Check the porting guide for Qt6: https://doc.qt.io/qt-6/portingguide.html
*Ensure the example complies with the Qt 6 porting guides for each module the example is using: https://doc.qt.io/qt-6/modulechanges.html
*Check the best practises for QtQML & QtQuick: https://doc-snapshots.qt.io/qt6-dev/qtquick-bestpractices.html
*Do not use versions in QML import statements. This is usally a left-over from Qt 5.
 
==Leveraging C++17==
'''RECOMMENDED'''
 
*Prefer signal/slot connection with lambdas: https://doc.qt.io/qt-6/signalsandslots.html
*Check Qt Coding conventions: https://wiki.qt.io/Coding_Conventions
*Consider using clazy plugin (comes also with Qt Creator): https://www.qt.io/blog/porting-from-qt-5-to-qt-6-using-clazy-checks
 
==Naming the example, categorisation and adding keywords==
'''MANDATORY'''
 
*Don't add Qt module name or "Example" word to the example name. e.g. QtWidgets Application Example → Text editor application
**Note: If the part of the module name really needs to be used due to clearly describing functionality, that can still be done (e.g. Simple CoAP Client Example from Qt CoAP module)
*Add example application to correct category, for instance by adding '\meta category {Graphics & UI}' below '\examples'
 
  \example My Example
  \meta category {My Category}
 
Will end up as
  <categories>
    <category>My Category</category>
  </categories>
 
in the <example> section of the respective examples-manifest.xml file.
<br>
For further details see: https://codereview.qt-project.org/c/qt/qttools/+/447246
 
<br>
'''RECOMMENDED'''
 
*Confirm that the example shows up in Qt Creator welcome screen.
*Check that the example description text shown in Creator contains the right keywords for users to find it.
*Add appropriate tags to the example, for instance by adding '\meta tags {tag1,tag2}' below '\examples'.
*Tags are used to set additional keywords for the example which makes it easier to search in Qt Creator example view
**Don't add redundant information as tags which is already part of the category, example name or description
**Don't add platform information in the tags
 
==Visual Style==
'''MANDATORY'''
 
*Screen shots taken with high dpi resolution, minimum image size 440x320.
**Note: Images can be larger but should follow either 4:3 or 5:4 aspect ratio. Take meaningful image that gives an idea what the example is about.
*Icons should be suitable for high dpi screen with minimum size of 64x64.
 
<br>
'''RECOMMENDED'''
 
*Consider using Qt Quick over Qt Widgets but remember also dependency restrictions with module api examples.
*Create example's qml part to be Qt Design Studio compatible.
**Define purely declarative qml files with .ui.qml file extension.
**Test the project also in Qt Design Studio.
*Layouts should be tested on multiple platforms (macOS, Linux, Windows, iOS, Android, Embedded Linux (EGLFS) with full HD target screen resolution.
 
==Build System==
'''MANDATORY'''
 
*Our users should be able to build both with qmake and CMake. Both build systems should therefore work.
*Check that the example runs without any issues when opened in Qt Creator welcome screen, on all platforms. If additional steps are necessary, or examples do only run on some platforms, make sure that is is prominently stated in the example's documentation.
*CMake
**Do not use the 'find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)' pattern that is created for instance in CMakeLists.txt files created by Qt Creator wizards. This pattern is for keeping compatibility with Qt 5, which we don't strive for with Qt 6 examples.
**Use qt_standard_project_setup() instead enabling AUTOMOC, AUTOUIC manually
**Use PRIVATE linkage
 
<br>
'''RECOMMENDED'''
<br>
 
*Avoid including (re)sources outside of the example directory, as examples should be self-contained.
 
==Enable automated release testing==
'''RECOMMENDED'''
<br>
For enabling RTA testing add unique object names for all the UI objects
 
*https://doc.qt.io/qt-6/qobject.html#setObjectName
*https://kb.froglogic.com/squish/howto/explicitly-naming-objects/
 
==Misc==
'''MANDATORY'''
 
*Do not use QT_BEGIN_NAMESPACE ... QT_END_NAMESPACE for example types. This namespace is exclusively for types in the Qt libraries.

Latest revision as of 15:22, 20 November 2024

This page is obsolete and deprecated. For Qt 6 information, see Qt Examples Guidelines