C++20 Overview
Qt 6 officially requires C++17, however we are constantly working on supporting new C++ language features to make Qt faster and safer, and provide a better experience for our users.
This page gives a brief overview of C++20 features available in Qt.
Support for std::chrono
Various classes related to date and time have support for std::chrono features from older versions of C++. With the arrival of C++20, std::chrono
has added new calendar types, such as year_month_day, plus date and time representations, such as the system_clock and its time_point types. When Qt is built with C++20, it can now make use of these additions.
QDate and QDateTime now support conversion to and from the various calendar, date and date-time types, along with addition of duration types. QTimeZone now supports construction from a time_zone.
QSpan - a Qt version of std::span
The std::span class template is an addition to the standard library that provides a uniform way to access a contiguous portion of any contiguous container.
Using std::span
in the public APIs of Qt could provide significant advantages. However, Qt 6 only requires C++17, meaning it cannot have C++20 types in the API and ABI.
Qt 6.7 introduced QSpan - a Qt version of std::span
. The API of the class is compatible with the std version. QSpan and std::span
can be implicitly converted into each other. However, there are some differences between the classes. See the corresponding section in the QSpan class documentation for more details.
Additional important features
Qt has also adopted a few more features from C++20, such as:
- Q_CONSTINIT macro that expands to the C++20
constinit
keyword, or to compiler-specific attributes if they are available - Q_NODISCARD_CTOR macro that expands to the
[[nodiscard]]
attribute if the compiler supports[[nodiscard]]
on constructors - Q_NODISCARD_X and Q_NODISCARD_CTOR_X macros for
[[nodiscard("reason")]]
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.