summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qdebug.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Doc: Improve documentation of qDebug and friendsKai Köhne2025-07-291-1/+136
| | | | | | | | | | | | | | | | | | | | Document the QDebug stream operator variants separately, as part of QDebug (where they belong). Reorder the remaining documentation for better readability: Talk about the arguments and show an example first. Mention common placeholders like %s and %i for easier access. Give the details about the exact sink behavior later. Do not mention the default message logger behavior, as that is better documented centreally. Also, call the first argument of the printf() style debug format, to make it more obvious that it can contain placeholders and format options. Pick-to: 6.9 6.10 Change-Id: I370f490a524123c635d6c84feda385dad5174dcc Reviewed-by: Nicholas Bennett <nicholas.bennett@qt.io>
* Fix of files under src_corelib_io prefixOleksii Zbykovskyi2025-07-241-1/+9
| | | | | | | | | | | | Made all snippets in these files compilable Also fixed some documentation related to the snippets change. Removed qdebug docs file since it was not used anywhere except one file. Obviously, moved the text to that file. Task-number: QTBUG-137566 Change-Id: I914afc96d58617a04d03d4f6e9545ec1aa2a8eb8 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* QTextStream: prefer QStringView overload of Private::putString()Marc Mutz2025-07-191-1/+1
| | | | | | | | | | | | | This call is safer than the (ptr, n, bool=false) one, which may accidentally resolve to (view, bool) if decltype(ptr) is "wrong". This is in preparation of removing said putString() overload (and the bool parameter). Task-number: QTBUG-138520 Pick-to: 6.10 6.9 6.8 6.5 Change-Id: I93ff89322468558f7da723ae47a1d67852cc59e6 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Prefer QTextStreamPrivate::write(QStringView) over (ptr, n) [2/2]: restMarc Mutz2025-07-191-3/+3
| | | | | | | | | | | | | | | | | Replace the remaining calls to write(const QChar *, qsizetype) with calls that use QStringView. Requires adapting a QChar[2] (not null-terminate, and QStringView constructor scan for one). Chose to make it a char16_t literal instead, and make it constexpr as a drive-by. This removes the last caller of the write(p, n) overload, so remove it. Task-number: QTBUG-138520 Pick-to: 6.10 6.9 6.8 6.5 Change-Id: Iddfadc7cd7837a541e5840247f8812398807bcfe Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Prefer QTextStreamPrivate::write(QStringView) over (ptr, n) [1/2]: castsMarc Mutz2025-07-191-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | Replace calls that needed to reinterpret_cast arguments in order to call write(const QChar *, qsizetype) with calls that use QStringView. The QStringView ctor hides the casts. In both cases, the ranges are statically known to be valid (one is over a local buffer and the other over contents we've already inspected), so the old code cannot have depended on the write(p, n) behavior, inherited from QString::append(p, n), of silently ignoring invalid ranges. So this change is safe. Requires changing an if() into an if constexpr(): while the reinterpret_cast to QChar* compiles even for uchar* input, the QStringView ctor would not. This is in preparation of removing the write(p, n) overload completely. Task-number: QTBUG-138520 Pick-to: 6.10 6.9 6.8 6.5 Change-Id: Ic4bd0ca8743fe5d2cfc08e2caa3f2cbdad29abc3 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QTextStream: use write(QChar) moreMarc Mutz2025-07-141-4/+3
| | | | | | | | | | | | | | | | | | | | Replace write(&ch, 1) calls with write(ch) ones. The QChar overload, added in 31c6d9f04ba80e6776ae01cb0588e6bd228f7184, is safer, because it has less preconditions. With QTextStream being security-critical, we should target to use safer functions to do the same work, even if it introduces a bit of git history churn. The call from a different TU (qdebug.cpp) means we need to remove the lying inline keywords from both declaration and definition of write(QChar), because GCC -Werrors on them. As a drive-by, remove a use of QLatin1Char, in preparation of moving from QChar to char16_t, eventually. Pick-to: 6.10 6.9 6.8 Change-Id: I97b4c8c68a4ee0d4b821c4d2ec4a9dd6f44dceb0 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* De-pessimize QDebug::putByteArray()Marc Mutz2025-07-151-3/+8
| | | | | | | | | | | | | | | QTextStreamPrivate has had putString() overloads for QUtf8StringView (since e96a311334a5c70d5ffcc2ca5c10919952b99636) and QLatin1StringView (since 8515aa18716779985a5955292524fd683528c576) for ages, so use those instead of unconditionally converting to QString, as the original code from 62b752b3a2c9a69b5eb9a41b98293e83de347958 did. As a drive-by, turn the ternary operator into a switch to enable -Wswitch. Pick-to: 6.10 6.9 6.8 Change-Id: I5f250826704c0fdd4c32a4b88e3d0b4dda878318 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Mark QDebug as security-criticalMatthias Rauter2025-06-191-0/+1
| | | | | | | | | | | | | | | | QDebug can be used to print strings from untrusted sources. Since QDebug modifies these strings to improve their appearance, it parses their contents as part of the formatting process. This behavior can be exploited by attackers to trigger bugs in QDebug, making it a potential attack vector. Therefore, mark it as security-critical. Header and implementation files are marked. QUIP: 23 Pick-to: 6.10 6.9 6.8 Task-number: QTBUG-135187 Change-Id: I3d751f196a110354ef6c81aa9d2af5e2c88a9b6a Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* Correct two misleading commentsEdward Welbourne2025-05-221-2/+2
| | | | | | | | | | | | Of course ucs4 >> 32 would be zero, as it's only a 32-bit value to begin with; and the pattern of later bytes actually processed makes quite clear what offsets the two short-cut ones really come from. Brought to light while reviewing assessment of security level. Task-number: QTBUG-135187 Change-Id: I8af6b5c935de400f3ac1c2efae297b0333891d64 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Long live \constraints!Marc Mutz2025-02-281-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We have divergence in the way we document function, operator and constructor constraints. About half use \note, while the other doesn't. Some say "if and only if" while others say just "participates only if". So add a qdoc macro, \constraints, to semantically mark up these constraints. It expands to a section titled `Constraints`, and uses a predefined sentence (prefix) for constraints. Documentation for constraints is moved to the end of the comment blocks to separate them from the rest of the text. Apply them to all the standard-ish constraint documentation blocks (grepped for "participate"). I didn't look for other, one-off, ways documentation authors may have documented constraints, but I'm also not aware of any. Re-wrap lines only if the result fits into a single line. As a drive-by, drop additional "if"s, as in "only if X and -if- Y" to make the texts work with the `Constraints` section. Fixes: QTBUG-106871 Pick-to: 6.9 6.8 6.5 Change-Id: I18c2f9f734474017264e49165389f8c9c7f34030 Reviewed-by: Kai Köhne <kai.koehne@qt.io> Reviewed-by: Paul Wicking <paul.wicking@qt.io> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Fix docs for new QDebug streaming operators of std containersIvan Solovev2025-01-171-1/+1
| | | | | | | | | | | | | | | | Added the missing function declarations to the #if Q_QDOC part of the header. Also fixed a typo in the std::unordered_map docs. Amends 850d4895be565931d18c92e5e2f9a33b7f26de6d, 0c96528e8d43ad4309bdca14b179a5045984655a, a9fe57fefaac0cb047e4c02e0b8c8f8327e0a58c, and a8c9a5617c72ad2e55bf497df6ff2c2e141cbdef. Found in Qt 6.9 API review. Pick-to: 6.9 Change-Id: I792023b506e2afdbdca4bca3197887e50c98a788 Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* Provide docs for std::array QDebug streaming operatorIvan Solovev2025-01-171-0/+9
| | | | | | | | | | | Amends b294927a1270f7d0c5aaf0bbe93b617ac995e149. Found in Qt 6.9 API review. Pick-to: 6.9 Change-Id: Iab64d52c506030dd755d61edc376bb47865478ff Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* QTextStream: port from QScopedPointer to unique_ptrMarc Mutz2024-12-191-2/+2
| | | | | | | | | | | In preparation of adding QT_NO_SCOPED_PONTER, which would be rather pointless for users if public headers continued to mention the type. Pick-to: 6.9 6.8 Task-number: QTBUG-132213 Change-Id: I6539e83158ab34e4fa4bd22b6d0ac5629a3b6db9 Reviewed-by: Ahmad Samir <a.samirh78@gmail.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QDebug: make std::optional stream operator SCARYMarc Mutz2024-12-181-3/+2
| | | | | | | | | | | | | | | | | | | | Piggy-back on the recently-added, type-erased, std::tuple stream operator to handle std::optional the same way. While std::optional doesn't support the Tuple Protocol, and we therefore can't use putTuple() directly, we can still use putTupleImplImpl() if we set up its arguments manually. [ChangeLog][Potentially Source-Incompatible Changes][QDebug] The std::optional streaming operator is now a member of QDebug, not a free function. This breaks users that rely on the exact definition of the operator (e.g. `operator<<(d, opt)`). A backwards-compatible fix is to call the operator with infix notation (d << opt) only, and to avoid const QDebug objects. Pick-to: 6.9 Change-Id: Ib040d65953ca9d3892aee5bdb597d6d30a9694b1 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* QDebug: add refinements to qDebug support for stl containersDheerendra Purohit2024-12-121-5/+4
| | | | | | | | Refinements of the stl containers based on the comments. Fixes: QTBUG-131766 Change-Id: Iddca031a7b63cc24a3d4a1fdede02b8968e95be9 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QDebug: add streaming operators for std::multisetDheerendra Purohit2024-11-261-0/+9
| | | | | | | | | | | | | | The stream insertion operator for QDebug is not overloaded to handle std::multiset Overload the stream insertion operator for QDebug to handle std::multiset [ChangeLog][QtCore][QDebug] Added support for std::multiset. Fixes: QTBUG-131428 Change-Id: I7e3b721afe88d68c99c44c0d7cc9ee7711c169c8 Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* QDebug: add streaming operators for std::setDheerendra Purohit2024-11-221-0/+9
| | | | | | | | | | | | | | The stream insertion operator for QDebug is not overloaded to handle std::set Overload the stream insertion operator for QDebug to handle std::set [ChangeLog][QtCore][QDebug] Added support for std::set. Fixes: QTBUG-130574 Change-Id: I8e1589589c8f23318bf5073609995f7da4ea1108 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QDebug: add streaming operators for std::unordered_setDheerendra Purohit2024-11-201-0/+10
| | | | | | | | | | | | | | The stream insertion operator for QDebug is not overloaded to handle std::unordered_set Overload the stream insertion operator for QDebug to handle std::unordered_set [ChangeLog][QtCOre][QDebug] Added support for std::unordered_set. Fixes: QTBUG-130481 Change-Id: I75a1f62f9ecb6b06ba45cc00d789cd3f3886b4c7 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QDebug: add streaming operators for std::unordered_mapDheerendra Purohit2024-11-191-0/+9
| | | | | | | | | | | | | | The stream insertion operator for QDebug is not overloaded to handle std::unordered_map Overload the stream insertion operator for QDebug to handle std::unordered_map [ChangeLog][QtCore][QDebug] Added support for std::unordered_map. Fixes: QTBUG-130290 Change-Id: I96e82f90c310dcac4a6e4d35651fb1adb6d6293a Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Create qdoc macros for C++ class docs 1.2: member-swap(), simplified phrasingMarc Mutz2024-11-081-3/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We have some patterns for how to document certain functions, but we also vary the sentences a lot, and you have to look up one documentation piece and copy it, essentially. If we ever want to change them, we end up with shotgun surgery. So apply DRY to the documentation and start a collection of macros to help with repetitive C++ class documentation tasks. The first macro is for member-swap(), and this second patch is for documentation that used the simplified phrasing ("Swaps this X with \a other."), which this patch adopts as the text for \memberswap, too, because it doesn't repeat the macro argument, making it easier to find a grammatically-fitting argument than in the traditional phrasing. This doesn't change the documentation, except as follows: * standardizes on simpified instead of traditional phrasing for docs that already use the \memberswap macro * adds the "very fast and never fails" blurb, if it was missing * changes the function's argument name to `other`, as required by the macro. Task-number: QTBUG-129573 Pick-to: 6.8 6.7 6.5 6.2 Change-Id: I1123e783ce0da76c5997ff74007d77504ac5b334 Reviewed-by: Topi Reiniö <topi.reinio@qt.io> Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* QDebug: add streaming operators for std::tupleMarc Mutz2024-11-051-0/+35
| | | | | | | | | | | Unlike the existing one for std::pair, make the operator SCARY, using the newly-added StreamTypeErased type-erasure (added in 5cdd1f594d26e1d4f84b00741be1ab7231458512). [ChangeLog][QtCore][QDebug] Can now stream std::tuple. Change-Id: I46670ac32eaee7f0ea5f4543ebcf59e19b394166 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* QDebug: improve support for printing 64-bit QFlagsThiago Macieira2024-10-091-2/+12
| | | | | | | | | | | Like the 32-bit version, we add an explicitly-exported non-template overload. And we can call the 64-bit implementation from the 32-bit one to save in code generation inside QtCore. Task-number: QTBUG-111926 Change-Id: I8a96935cf6c742259c9dfffd17e9928218333c04 Reviewed-by: Ahmad Samir <a.samirh78@gmail.com> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QDebug: cast the QFlags value to the right-sized unsigned type (1/2)Thiago Macieira2024-08-101-3/+3
| | | | | | | | | | | | | | | | | | | | | | This change fixes three problems in the non-Q_ENUM overload. First, the printing of the sign bit for a signed flag. This is correct, but unexpected: QFlags(0x1|0x2|-0x80000000) By using unsigned types, we'll print instead: QFlags(0x1|0x2|0x80000000) Second, shifting into the sign bit is UB, so we remove the problem by not having a sign bit at all. Third, this provides an out-of-line non-template overload of the implementation for unsigned QFlags, thereby avoiding an unnecessary instantiation of the template function qt_QMetaEnum_flagDebugOperator() in user code. Pick-to: 6.8 Change-Id: I8a96935cf6c742259c9dfffd17e992caa315e1d3 Reviewed-by: Ahmad Samir <a.samirh78@gmail.com> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Introduce QT_NO_QSNPRINTF and mark QtCore as qsnprintf-freeMarc Mutz2024-08-031-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ... except, of course, the implementation file, which therefore has to be excluded from PCH'ed builds. Remove qvsnprintf.cpp from libbootstrap, as it's no longer needed after porting all five uses of qsnprintf() in QtCore to C++11's std::snprintf(), which even Windows implements with std behavior. The reason we're removing the function is that std::snprintf() is the better alternative: qsnprintf() just introduces even more platform variance than any implementation-defined behavior of C or C++ snprintf(). To wit: - On Windows, the return value is sometimes "wrong" (cf. Windows-specific qsnprintf() tests in tst_qbytearray.cpp) - On WASM and at least some Android configurations, it is incorrectly implmented using the QString::asprintf().toLocal8Bit() work-around, even though both platforms have a working snprintf(). QString::asprintf() is implemented in Qt itself, so has some differences: - the `a` format for hex floats is not supported - %ls expects char16_t*, not wchar_t* (these are, in general, not the same width) We will deprecate these functions in 6.9, but before we do, we need to get the Qt code in order, and that's where this macro comes in. [ChangeLog][QtCore] Added the QT_NO_QSNPRINTF macro to disable qsnprintf() and qvsnprintf(), which will also be deprecated in 6.9. See the documentation for details why we take this step. Task-number: QTBUG-127110 Pick-to: 6.8 Change-Id: I4e1c1f213bcfd615f83387f5f51e77fa1ff2062e Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Add QDebug printing for the std/Qt::<name>_ordering typesTatiana Borisova2024-08-011-0/+49
| | | | | | | | [ChangeLog][QtCore][QDebug] Added possibility to print {std/Qt} weak/partial/strong_ordering values with QDebug << operator. Change-Id: Ie880cb34c19f79a404c692c2322b3460d72bfde4 Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* Doc: Fix undocumented parameter QDoc warningPaul Wicking2024-08-011-1/+2
| | | | | Change-Id: Iee12e8500e1a596cad7d1f256eea02d22bf156ef Reviewed-by: Topi Reiniö <topi.reinio@qt.io>
* Long live QDebug::toBytes()!Marc Mutz2024-07-231-0/+22
| | | | | | | | | | | | | | | | | | | | | | | | | I've seen over and over again how test authors are plagued by the impedance mismatch between their 8-bit actual data and the result of QString::toString() being in UTF-16. They invariably ditch their 8-bit inputs and go to QString, but the mere fact that they start out with 8-bit input and then run into problems means we have a gaping API hole here. QTest::toString() also suffers from this. So add the option to a) construct a QDebug object over a QByteArray (already supported by underlying QTextStream) and b) to stream into QByteArray like toString() streams into QString. Finally, make QTest::toString() use the new toBytes() function instead of the old toString() one. This saves 1% (91122→90248) in tst_tostring exeutable size on optimized Linux AMD64 GCC 9 builds. [ChangeLog][QtCore][QDebug] Added ctor from QByteArray* and a static toBytes() function. Change-Id: I2b021513d6427a1a961f39e751eaf4faaf527ba8 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QDebug: make toString() SCARYMarc Mutz2024-07-211-0/+11
| | | | | | | | | | | | Extract the non-template-dependent code into an out-of-line function and pass the actual streaming operation as a callback. Saves 4% (174811→167936) in executable size for tst_qdebug and 2.7% (93639→91122) for tst_tostring on Linux GCC 9 AMD64 release builds. Pick-to: 6.8 Change-Id: If232e5b26c66981ffcb614f1bdb7007c71e879bf Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Fix signature of QDebug::toString() (again)Marc Mutz2024-07-201-1/+1
| | | | | | | | | | | | | | | | | | | | | | | There are zero QDebug operators that take an rvalue RHS, so there's no need to make toString() perfectly forwarding. It just causes four¹ different versions of the identical function to be instantiated. Not all compilers can merge the binary representations and those that try, violate the standard (same address for different functions). ¹ {rvalue, lvalue} × {const, non-const} Fix by taking by cref. Amends 40976532158fc49be45bb976455f48e98f9690cf. [ChangeLog][Potentially Source-Incompatible Changes][QtCore][QDebug] The toString() static function no longer allows the called operator<<() to modify the argument. No Qt-provided operator<<() does that, and operators that do are probably buggy. Pick-to: 6.8 Change-Id: Iac1ee9d29f93fd4840b75ffe363d354a2d19a96e Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Logging: introduce QInternalMessageLogContext to hold current contextThiago Macieira2024-03-271-2/+3
| | | | | | | | | | | | | | QMessageLogContext is a primitive type that may be extended in the future with more fields (it has been at version 2 since commit 6d166c88220ee09821b65fb2b711fa77a5312971, though that did not extend the struct's size). This introduces a QInternalMessageLogContext which is used in before all our calls to qt_message_output(). Currently there's no difference and no way to tell that the internal version is used. Change-Id: I01ec3c774d9943adb903fffd17b7d5abc0052207 Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
* Remove unnecessary #undef about q{Debug,Info,Warning,Critical,Fatal}Thiago Macieira2024-03-041-7/+0
| | | | | | | | | | | | | | | | | | The ones in qlogging.cpp were copied to it from qglobal.cpp in commit 23688d8942895507f4bc1517dd3c161134f4f9d0. They existed in qglobal.cpp like in qdebug.cpp since the beginning of the public history. The one in qdebug.cpp already made no sense in Qt 4 times, because qdebug.cpp was a documentation-only source (no actual C++ code). The #undefs from qglobal.cpp hadn't been necessary since commit d394ca7f27197cfbfc28eb9a08eb0db261dd9d3d, the global functions qDebug(), qWarning(), qCritical(), etc. were replaced by member functions in QMessageLogger whose names did not match the macros. Pick-to: 6.7 Change-Id: I50e2158aeade4256ad1dfffd17b1c62f23eca4db Reviewed-by: Kai Köhne <kai.koehne@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* Doc: Fix documentation issues for Qt CoreTopi Reinio2023-12-191-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Fix template arguments in \fn signatures for Qt::compareThreeWay() functions. * Fix template arguments in \fn signatures for QDebug::operator<<() functions. * Fix \sa links to specific overloads of QSpan functions. * Fix \sa links to specific overloads of QFileInfo::fileTime(). * Remove references to 'Custom Type Example' (example has been removed). * Fix linking to 'JSON Save Game' example. * Fix references to 'Queued Custom Type' example. * Fix linking to QCryptographicHash::Algorithm. * Fix linking to Qt Qml module. * Fix undocumented parameters in qHypot(). Pick-to: 6.7 Change-Id: If9eb9978a14e147f003672a682972b319454c311 Reviewed-by: Luca Di Sera <luca.disera@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* Long live QDebug::operator<<(q(u)int128)!Marc Mutz2023-12-091-0/+99
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Replace the ad-hoc implementation of QTest::toString() in tst_qglobal.cpp with a QDebug stream operator, so the QTest::toString() fall-back to QDebug::toString() kicks in. Since the ABI issues revolving around the new int128 types are not known, yet, avoid baking the types into the ABI by a) making the operators constrained templates¹ and b) passing though void* to the exported helpers. These functions return an error message if Qt was compiled without support for int128. Use the Thiago Trick™ (leaving obviouly dead code around for the compiler to remove without warning) to expose more code to more compilers. This appears to work elsewhere in Qt, so I hope it does here, too. This completes the minimum qint128 support so we're able to debug code and write tests that use these types. ¹ Templates, unlike inline member functions of wholly-exported classes, never² become part of the ABI. ² <insert here the convoluted scenario under which this is false> Fixes: QTBUG-117011 Change-Id: Ia4e56d26c6ffd18b7d69a7ceaed65b2211d258b2 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* QDebug: remove QPair streaming docsMarc Mutz2023-12-071-8/+0
| | | | | | | | | QPair _is_ std::pair. If this wasn't a fake-definition under #ifdef Q_QDOC, the compiler would have complained long ago. Pick-to: 6.6 6.5 Change-Id: Idfe589ff13115d3d908572a17b849f634ec86787 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* qDebug: add support for std::optional and std::nullopt_tDavid Faure2023-11-221-0/+16
| | | | | | | | | | [ChangeLog][QtCore][QDebug] Added support for std::optional and std::nullopt_t Change-Id: I1e6196adb408401cae8776cd0c60af294a39a83f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Remove Custom Type Example and Custom Type Sending ExampleRym Bouabid2023-10-041-1/+1
| | | | | | | | | | | | | | | | | | | | | The whole Q_DECLARE_METATYPE part is superfluous in these two examples, as QVariant works with any type as long as it is copy-constructible. And QVariant will call the equivalent of qRegisterMetaType, so that doesn't need to happen, either. Showing how to integrate the type with qDebug is fine in theory, but also a repetition of content that can be found in other places. Given that there isn't much else being shown in these two examples, it's better to remove them from examples and move them to manual tests. Some parts of "Custom Type Example" were used as snippets in other documentations under qtbase/src/corelib. So, they were added in customtypeexample.cpp file in the snippets folder. Fixes: QTBUG-117001 Pick-to: 6.6 6.5 Change-Id: I45b16338912e3f7394cbb5169642bd31af32d5e1 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* QDebug: rewrite timeUnit() into putTimeUnit()Marc Mutz2023-07-101-6/+11
| | | | | | | | | | | | This avoids us committing to the QByteArray return value, which is overkill for short strings. Instead, pull the streaming of the unit behind the ABI boundary, so we're free to change the implementation to either stream directly or use SSO'ed std::string. Pick-to: 6.6 Change-Id: I10927acb9d64077d9018b667958ca16be218012a Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* QDebug: add getter/setter for noQuotesMarc Mutz2023-07-051-0/+23
| | | | | | | | | | | | | | There were setters (quote(), noquote()), but, unlike space()/nospace(), there was no getter. Add the getter, and, for symmetry, a parametrized setter, too. [ChangeLog][QtCore][QDebug] Added setQuoteStrings()/quoteStrings() to access and manipulate the quote()/noquote() state. Change-Id: I1b73138819b4d02726a6ef862c190206431ccebc Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Move the formatting of <chrono> durations to QDebug & QtTestThiago Macieira2023-05-061-0/+98
| | | | | | | | | | | | [ChangeLog][QtCore][QDebug] Added pretty formatting of C++ <chrono> durations. [ChangeLog][QtTest] Added pretty formatting of C++ <chrono> durations for QCOMPARE expressions. Change-Id: I3b169860d8bd41e9be6bfffd1757cc087ba957fa Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* QtMiscUtils: add isAsciiPrintable() helperAhmad Samir2023-03-181-6/+3
| | | | | | | | | | | | | | | | | | | | | | - isAsciiPrintable: borrowed the logic from isPrintable(uchar) in qdebug.cpp, now isPrintable(uchar) calls isAsciiPrintable - Replace ::isspace() with ascii_isspace() from qlocale_p.h Functions from ctype.h have a couple of issues: - they're locale-dependent, which isn't what's required here, the code is only interested in ASCII - their args should be representable as uchar or EOF otherwise it's undefined behavior An Early-Warning could use something like: grep -rP "\b(isalnum|isalpha|isblank|iscntrl|isdigit|islower|isgraph|\ "isprint|ispunct|isspace|isupper|isxdigit|tolower|toupper)\b" Pick-to: 6.5 Task-number: QTBUG-111262 Change-Id: I1f47f41bd56735297078ff0d0ddc2ebf999abf8b Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Replace ushort*/uint* with char16_t*/char32_t* in private API [1]Ahmad Samir2023-03-151-9/+7
| | | | | | | Task-number: QTBUG-110403 Pick-to: 6.5 Change-Id: Ie20a831f22212d56659cf3c6940d17134ab5f2c5 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QMetaEnum: fix narrowing warnings related to valueToKey*()Ahmad Samir2023-03-131-3/+2
| | | | | | | | | | | | | | | | | valueToKey*() takes an int, and QMetaEnum internally assumes the underlying type of an enum is not bigger than int. Using static_cast as it's easier to search for it in the codebase if needed. Found by compiling with -Wshorten-64-to-32. Drive-by change: remove qdoc \fn command for qt_QMetaEnum_debugOperator, it's an internal method and defined right under the doc block (the signature still said "int" but it's qint64). Change-Id: Ia6abc85173bf94c0a8c56663481d83d3a998f68d Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QDebug: fix std::string/view stream operators; add u8 versionsMarc Mutz2023-03-021-67/+12
| | | | | | | | | | | | | | | | | | | | | | Make them templates, for two reasons: - so they can accept std::pmr types and, in general, any basic_string with custom allocators and char_traits - to break overload ambiguities with the Qt string view types Also, add the missing C++20 char8_t overloads. Also, avoid creation of a QString in the sizeof(wchar_t) == 2 case (Windows). Add a comment to optimize for the sizeof(wchar_t) != 2 case later. Found in API review. Pick-to: 6.5 Change-Id: I30139520f582a38863a0936f8eca4b1ed33e37c8 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QDebug: Support standard strings and string views directlyVille Voutilainen2022-09-271-0/+73
| | | | | | | | | | [ChangeLog][QtCore][QDebug] QDebug now supports printing std::strings and std::string_views (and their wide, u16, and u32 variants) directly. Task-number: QTBUG-96878 Change-Id: I7baf4fe688bfff50580b1cee9417af13949374cc Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QDebug: finish porting to qsizetype/size_tMarc Mutz2022-08-211-1/+1
| | | | | | | | | | | | | | | Port two variables from int/uint to qsizetype/size_t. These don't cause problems, because their possible ranges are limited, however, int/uint variables are a code smell these days, so replace them nonetheless. [ChangeLog][QtCore][QDebug] Fixed issues on 64-bit platforms when streaming containers (incl. strings) of more than 2Gi elements. Pick-to: 6.4 6.3 6.2 Task-number: QTBUG-103525 Change-Id: Ica6c5a6a062990306280fb713c47adb2053b752d Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QDebug: finish porting put{String,ByteArray} to qsizetypeMarc Mutz2022-08-211-2/+3
| | | | | | | | | | | | | | The underlying QTextStream seems to support qsizetype-sized data and the private API of QDebug that is under consideration in this patch takes size_t, but, as so often, there're int/uint casts in-between that break things. Widen the int/uint casts to qsizetype/size_t, respectively. Pick-to: 6.4 6.3 6.2 Task-number: QTBUG-103525 Change-Id: I10bca093dc2d6f136871c94ca43f5b42fd1c8971 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QDebug: port putEscapedString() from int to size_tMarc Mutz2022-08-211-4/+4
| | | | | | | | | | | | | | | All callers of the function pass size_t values, so remove the impedance mismatch and preserve the value. Adjust local variable runLength to qsizetype, because with this change the int variable may now overflow, which would cause infinite looping. Adjust callers to not perform narrowing conversions. Pick-to: 6.4 6.3 6.2 Task-number: QTBUG-103525 Change-Id: I2a9d3301118855fc95245a55bf64de6c46fa2f51 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Port QtDebugUtils::toPrintable() to qint64/qsizetypeMarc Mutz2022-08-211-3/+4
| | | | | | | | | | Some callers pass qint64 arguments to the len parameter, so take the size as qint64, not qsizetype, to avoid silent truncation. Pick-to: 6.4 6.3 6.2 Task-number: QTBUG-103525 Change-Id: I4bc5673297f24aea0cfc9d20887dc8a877743214 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Use SPDX license identifiersLucie Gérard2022-05-161-39/+3
| | | | | | | | | | | | | Replace the current license disclaimer in files by a SPDX-License-Identifier. Files that have to be modified by hand are modified. License files are organized under LICENSES directory. Task-number: QTBUG-67283 Change-Id: Id880c92784c40f3bbde861c0d93f58151c18b9f1 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
* QtCore: Replace remaining uses of QLatin1String with QLatin1StringViewSona Kurazyan2022-03-261-1/+1
| | | | | | | Task-number: QTBUG-98434 Change-Id: Ib7c5fc0aaca6ef33b93c7486e99502c555bf20bc Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Marc Mutz <marc.mutz@qt.io>