diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp index 748ca60661..f4fac3f35e 100644 --- a/src/corelib/global/qlogging.cpp +++ b/src/corelib/global/qlogging.cpp @@ -1667,7 +1667,7 @@ static bool android_default_message_handler(QtMsgType type, #ifdef Q_OS_WIN static void win_outputDebugString_helper(QStringView message) { - const int maxOutputStringLength = 32766; + const qsizetype maxOutputStringLength = 32766; static QBasicMutex m; auto locker = qt_unique_lock(m); // fast path: Avoid string copies if one output is enough @@ -1675,9 +1675,9 @@ static void win_outputDebugString_helper(QStringView message) OutputDebugString(reinterpret_cast(message.utf16())); } else { wchar_t *messagePart = new wchar_t[maxOutputStringLength + 1]; - for (int i = 0; i < message.length(); i += maxOutputStringLength) { - const int length = std::min(message.length() - i, maxOutputStringLength); - const int len = message.mid(i, length).toWCharArray(messagePart); + for (qsizetype i = 0; i < message.length(); i += maxOutputStringLength) { + const qsizetype length = std::min(message.length() - i, maxOutputStringLength); + const qsizetype len = message.mid(i, length).toWCharArray(messagePart); Q_ASSERT(len == length); messagePart[len] = 0; OutputDebugString(messagePart); diff --git a/src/corelib/text/qanystringview.h b/src/corelib/text/qanystringview.h index ff1f8a4050..68754931e9 100644 --- a/src/corelib/text/qanystringview.h +++ b/src/corelib/text/qanystringview.h @@ -217,12 +217,8 @@ public: // [[nodiscard]] constexpr bool isNull() const noexcept { return !m_data; } [[nodiscard]] constexpr bool isEmpty() const noexcept { return empty(); } -#if QT_DEPRECATED_SINCE(6, 0) - [[nodiscard]] - Q_DECL_DEPRECATED_X("Use size() and port callers to qsizetype.") - constexpr int length() const /* not nothrow! */ - { return Q_ASSERT(int(size()) == size()), int(size()); } -#endif + [[nodiscard]] constexpr qsizetype length() const noexcept + { return size(); } private: [[nodiscard]] friend inline bool operator==(QAnyStringView lhs, QAnyStringView rhs) noexcept diff --git a/src/corelib/text/qanystringview.qdoc b/src/corelib/text/qanystringview.qdoc index c1a1681695..cb98fb0052 100644 --- a/src/corelib/text/qanystringview.qdoc +++ b/src/corelib/text/qanystringview.qdoc @@ -322,17 +322,11 @@ /*! \fn int QAnyStringView::length() const - \obsolete - Use size() instead, and port callers to qsizetype. - Same as size(), except that it returns the result as an \c int. + Same as size(). This function is provided for compatibility with other Qt containers. - \warning QAnyStringView can represent strings with more than 2\sup{31} characters. - Calling this function on a string view for which size() returns a value greater - than \c{INT_MAX} constitutes undefined behavior. - \sa size() */ diff --git a/src/corelib/text/qbytearrayview.h b/src/corelib/text/qbytearrayview.h index 4934294a81..02ce49613e 100644 --- a/src/corelib/text/qbytearrayview.h +++ b/src/corelib/text/qbytearrayview.h @@ -291,12 +291,8 @@ public: // [[nodiscard]] constexpr bool isNull() const noexcept { return !m_data; } [[nodiscard]] constexpr bool isEmpty() const noexcept { return empty(); } -#if QT_DEPRECATED_SINCE(6, 0) - [[nodiscard]] - Q_DECL_DEPRECATED_X("Use size() and port callers to qsizetype.") - constexpr int length() const /* not nothrow! */ - { Q_ASSERT(int(size()) == size()); return int(size()); } -#endif + [[nodiscard]] constexpr qsizetype length() const noexcept + { return size(); } [[nodiscard]] constexpr char first() const { return front(); } [[nodiscard]] constexpr char last() const { return back(); } diff --git a/src/corelib/text/qbytearrayview.qdoc b/src/corelib/text/qbytearrayview.qdoc index 36571e53d4..91048c5dad 100644 --- a/src/corelib/text/qbytearrayview.qdoc +++ b/src/corelib/text/qbytearrayview.qdoc @@ -470,23 +470,13 @@ \sa empty(), isEmpty(), isNull() */ -#if QT_DEPRECATED_SINCE(6, 0) /*! \fn int QByteArrayView::length() const - \obsolete - Use size() and port callers to qsizetype. - Same as size(), but returns the result as an \c int. - - This function is provided for compatibility with other Qt containers. - - \warning QByteArrayView can represent data with more than 2\sup{31} bytes. - Calling this function on a byte array view for which size() returns a value greater - than \c{INT_MAX} constitutes undefined behavior. + Same as size(). \sa empty(), isEmpty(), isNull(), size() */ -#endif /*! \fn char QByteArrayView::operator[](qsizetype n) const diff --git a/src/corelib/text/qstringview.cpp b/src/corelib/text/qstringview.cpp index 1c3249fbfb..e003f257d7 100644 --- a/src/corelib/text/qstringview.cpp +++ b/src/corelib/text/qstringview.cpp @@ -130,11 +130,6 @@ QT_BEGIN_NAMESPACE \typedef QStringView::size_type Alias for qsizetype. Provided for compatibility with the STL. - - Unlike other Qt classes, QStringView uses qsizetype as its \c size_type, to allow - accepting data from \c{std::basic_string} without truncation. The Qt API functions, - for example length(), return \c int, while the STL-compatible functions, for example - size(), return \c size_type. */ /*! @@ -530,14 +525,10 @@ QT_BEGIN_NAMESPACE /*! \fn int QStringView::length() const - Same as size(), except returns the result as an \c int. + Same as size(). This function is provided for compatibility with other Qt containers. - \warning QStringView can represent strings with more than 2\sup{31} characters. - Calling this function on a string view for which size() returns a value greater - than \c{INT_MAX} constitutes undefined behavior. - \sa empty(), isEmpty(), isNull(), size() */ diff --git a/src/corelib/text/qstringview.h b/src/corelib/text/qstringview.h index c0082b70b5..e34418e956 100644 --- a/src/corelib/text/qstringview.h +++ b/src/corelib/text/qstringview.h @@ -446,8 +446,8 @@ public: [[nodiscard]] const_iterator constEnd() const noexcept { return end(); } [[nodiscard]] constexpr bool isNull() const noexcept { return !m_data; } [[nodiscard]] constexpr bool isEmpty() const noexcept { return empty(); } - [[nodiscard]] constexpr int length() const /* not nothrow! */ - { return Q_ASSERT(int(size()) == size()), int(size()); } + [[nodiscard]] constexpr qsizetype length() const noexcept + { return size(); } [[nodiscard]] constexpr QChar first() const { return front(); } [[nodiscard]] constexpr QChar last() const { return back(); } private: diff --git a/src/corelib/text/qutf8stringview.h b/src/corelib/text/qutf8stringview.h index 5069bf7b07..a49aa08e4c 100644 --- a/src/corelib/text/qutf8stringview.h +++ b/src/corelib/text/qutf8stringview.h @@ -306,12 +306,8 @@ public: // [[nodiscard]] constexpr bool isNull() const noexcept { return !m_data; } [[nodiscard]] constexpr bool isEmpty() const noexcept { return empty(); } -#if QT_DEPRECATED_SINCE(6, 0) - [[nodiscard]] - Q_DECL_DEPRECATED_X("Use size() and port callers to qsizetype.") - constexpr int length() const /* not nothrow! */ - { return Q_ASSERT(int(size()) == size()), int(size()); } -#endif + [[nodiscard]] constexpr qsizetype length() const noexcept + { return size(); } private: [[nodiscard]] static inline int compare(QBasicUtf8StringView lhs, QBasicUtf8StringView rhs) noexcept diff --git a/src/corelib/text/qutf8stringview.qdoc b/src/corelib/text/qutf8stringview.qdoc index 8ff208ff23..36e09421a3 100644 --- a/src/corelib/text/qutf8stringview.qdoc +++ b/src/corelib/text/qutf8stringview.qdoc @@ -526,17 +526,11 @@ /*! \fn int QUtf8StringView::length() const - \obsolete - Use size() and port callers to qsizetype. - Same as size(), except returns the result as an \c int. + Same as size(). This function is provided for compatibility with other Qt containers. - \warning QUtf8StringView can represent strings with more than 2\sup{31} code points. - Calling this function on a string view for which size() returns a value greater - than \c{INT_MAX} constitutes undefined behavior. - \sa empty(), isEmpty(), isNull(), size() */