diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp index a690aac9360..5a340530a93 100644 --- a/src/corelib/text/qstring.cpp +++ b/src/corelib/text/qstring.cpp @@ -2190,6 +2190,16 @@ inline char qToLower(char ch) \sa fromLatin1(), fromLocal8Bit(), fromUtf8() */ +/*! \fn QString::QString(const char8_t *str) + + Constructs a string initialized with the UTF-8 string \a str. The + given const char8_t pointer is converted to Unicode using the + fromUtf8() function. + + \since 6.1 + \sa fromLatin1(), fromLocal8Bit(), fromUtf8() +*/ + /*! \fn QString QString::fromStdString(const std::string &str) Returns a copy of the \a str string. The given string is converted @@ -5324,6 +5334,14 @@ QString QString::fromLocal8Bit(QByteArrayView ba) \sa toUtf8(), fromLatin1(), fromLocal8Bit() */ +/*! + \fn QString QString::fromUtf8(const char8_t *str) + \overload + \since 6.1 + + This overload is only available when compiling in C++20 mode. +*/ + /*! \fn QString QString::fromUtf8(const char8_t *str, qsizetype size) \overload diff --git a/src/corelib/text/qstring.h b/src/corelib/text/qstring.h index c6d97c9d513..5e215625c6b 100644 --- a/src/corelib/text/qstring.h +++ b/src/corelib/text/qstring.h @@ -386,6 +386,12 @@ public: QString(QChar c); QString(qsizetype size, QChar c); inline QString(QLatin1String latin1); +#if defined(__cpp_char8_t) || defined(Q_CLANG_QDOC) + Q_WEAK_OVERLOAD + inline QString(const char8_t *str) + : QString(fromUtf8(str)) + {} +#endif inline QString(const QString &) noexcept; inline ~QString(); QString &operator=(QChar c); @@ -746,6 +752,9 @@ public: return fromUtf8(QByteArrayView(utf8, !utf8 || size < 0 ? qstrlen(utf8) : size)); } #if defined(__cpp_char8_t) || defined(Q_CLANG_QDOC) + Q_WEAK_OVERLOAD + static inline QString fromUtf8(const char8_t *str) + { return fromUtf8(reinterpret_cast(str)); } Q_WEAK_OVERLOAD static inline QString fromUtf8(const char8_t *str, qsizetype size) { return fromUtf8(reinterpret_cast(str), size); }