summaryrefslogtreecommitdiffstats
path: root/src/corelib/doc/snippets
Commit message (Collapse)AuthorAgeFilesLines
* QDeadlineTimer: use new comparison helper macrosTatiana Borisova2024-04-181-6/+6
| | | | | | | | | | | Replace public friend operators operator==() and operator!=() of QDeadlineTimer to friend method comparesEqual(). Replace public friends operator<(),<=(),>(), etc of QDeadlineTimer to friend method compareThreeWay(). Task-number: QTBUG-120304 Change-Id: Ib855ccac9b31b54fe28b822f2985154608fefa27 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* QFileSystemEngine: make factory functions return unique_ptr<QABFE>Ahmad Samir2024-03-211-6/+12
| | | | | | | | | | | | | | | | This makes the ownership of the returned pointer clearer. It also matches reality, some call sites were already storing the pointer in a unique_ptr. Also shorten the function name to "createLegacyEngine", you have to read its docs anyway to figure out what it does. Drive-by changes: less magic numbers; use sliced(); return nullptr instead of `0`. Change-Id: I637759b4160b28b15adf5f6548de336887338dab Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* QAbstractFileEngineIterator: add `bool advance()` virtual methodAhmad Samir2024-03-201-10/+8
| | | | | | | | | | | | | | | | | | | | | | | And remove hasNext/next() methods. This remodels QAFEI to be like QFileSystemIterator. This better fits the logic in the newly added QDirListing class (which uses STL-style iterators). QFSFileEngineIterator: Initialize the internal nativeIterator in the constructor; also replace the advance() private method with an override for the advance() method inherited from the base class. QResourceFileEngineIterator: Override currentFileInfo(), with a QResouces the QFileInfo is created on demand if/when this method is called. This is the backend/private API, and QDirListing is the public API that can be used in a ranged-for to iterate over directory entries. Change-Id: I93eb7bdd64823ac01eea2dcaaa6bcc8ad868b2c4 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QAbstractFileEngine: add a path parameter to beginEntryList()Ahmad Samir2024-03-171-4/+5
| | | | | | | | | | | | | Change beginEntryList() to take a path parameter, which it passes on to the QAFEIterator constructor; setting the path at construction makes more sense, because typically the path isn't supposed to change during iteration, and this simplifies the code at the call site. Remove setPath(), the last usage in Qt repos was in QtCreator, and that has been ported away from it. Change-Id: I01baa688e0f9b582aacb63d7d98a794276e58034 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QAbstractFileEngine: make {begin,end}EntryList() return a unique_ptrAhmad Samir2024-03-171-2/+2
| | | | | | | | Makes ownership clearer. Change-Id: Ibb57ca900ef30b16d48964a977e997ba6705248b Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* Mention QChronoTimer in API docsAhmad Samir2024-03-032-1/+17
| | | | | Change-Id: Iaf9fb31994f1580b2051dbd0b1b8eef2a218aa39 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Timers: add Qt::TimerId enum classAhmad Samir2024-03-031-0/+13
| | | | | | | | | | | | | | | | | | | | | | | | Which will be used to represent timer IDs. Thanks to Marc for the idea to use "a strongly typed int". QTimer got a new id() method that returns Qt::TimerId (can't overload timerId()). Various classes in qtbase have a member named timerId(), but a new method is needed anyway in QTimer so id() it is (this is the reason QChronoTimer only has id() and no timerId()). Besides timer.timerId() has an extra "timer". This commit fixes the inconsistency between QObject using `0` timer id to indicate "failed to start", while QTimer::timerId() returned `-1` to indicate "timer is inactive". QTimer::id(), being a new method and all, now returns Qt::TimerId::Invalid, which has value `0`, so that the values match between the two classes. Extend the unittests to ensure QTimer::timerId()'s behavior is preserved. [ChangeLog][Core][QObject] Added Qt::TimerId enum class, that is used to represent timer IDs. Change-Id: I0e8564c1461884106d8a797cc980a669035d480a Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Add QChronoTimer, a timer with nanoseconds precisionAhmad Samir2024-03-031-1/+43
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The interval in QTimer is a QProperty of type int, which means it's limited to the number of milliseconds that would fit in an int (~24 days), this could cause overflow if a user constructs a QTimer with an interval > INT_MAX milliseconds. And it can't be easily changed to use qint64/std::chrono::nanoseconds: - changing the getters to return qint64 means user code would have narrowing conversions - the bindable QProperty interval can't be changed to qint64 during Qt6's lifetime without the risk of breaking user code - adding a new bindable QProperty that is qint64/nanoseconds is an option, but it has the complication of what to do with the int interval; set it when setInterval(milliseconds) is used by using saturation arithmetic? and what about notifying observers of the changed interval? Thus the idea of creating a new stop-gap class, QChronoTimer, as a cleaner solution. Both classes use QTimerPrivate. During the lifetime of Qt6, QTimer's interval range is about 24 days, whereas QChronoTimer's interval range is about 292 years (duration_cast<years>nanoseconds::max()). Currently the plan is to fold QChronotTimer back into QTimer in Qt7. Mark all QPropertyS in the new class as FINAL since they aren't intended to be overridden; this offers a performance boost for QML[1]. [1] https://lists.qt-project.org/pipermail/development/2024-February/044977.html [ChangeLog][QtCore] Added QChronoTimer, which uses a std::chrono::nanoseconds intervals, as a replacement for QTimer. Fixes: QTBUG-113544 Change-Id: I71697f4a8b35452c6b5604b1322ee7f0b4453f04 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* Add QDirListing, an STL-style iterator for directory entriesAhmad Samir2024-02-291-8/+50
| | | | | | | | | | | | | | | | | | | | | | | | This class offers a forward-only const_iterator, that matches the system low-level functions' logic (e.g. readdir()/dirstream logic). This iterator is a std::input_iterator_tag. QDirIterator uses Java-style iterators that have a couple of issues: - They don't fit the logic of the underlying native system functions (readdir()/__dirstream and co.), there is no way to know if there is a next entry except by advancing the iterator (calling readdir()) first - As a consequence of the above, two QFileInfo objects, current and next, had to be used to fit that paradigm; and the code always iterated/stat'ed an extra entry past the one we want, e.g. when filtering The next step is porting QAbstractFileEngineIterator and its subclasses to be like QFileSystemIterator, i.e. replace hasNext()/next() with a `bool advance()` virtual method. This is easier to reason about than the Java-style iterators, and is more in-line with the new class. Discussed-on: https://lists.qt-project.org/pipermail/development/2023-December/044745.html Change-Id: I8e696cefdca18d8c78f803efdb83a73dd43eb720 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Copy QDirIterator.{cpp,h} to QDirListing.{cpp,h}Ahmad Samir2024-02-291-0/+28
| | | | | | | To make it easier to follow the history in git. Change-Id: I094056c1ec130aeef77aa2d20289ab766bc25083 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QString/QByteArray: add slice() methodsAhmad Samir2024-02-292-0/+16
| | | | | | | | | [ChangeLog][QtCore][QString/QByteArray] Added slice() methods that work like sliced(), but modify the string/byte-array they are called on. Task-number: QTBUG-99218 Change-Id: I3075562983ef123d9aa022a2304c7e774cf2ea42 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Correct doc snippet licenseLucie Gérard2024-02-283-3/+3
| | | | | | | | | | | | | | All file under doc/snippet should be license as Documentation snippets and according to QUIP-18 [1] this is LicenseRef-Qt-Commercial OR BSD-3-Clause [1]: https://contribute.qt-project.org/quips/18 Pick-to: 6.7 Task-number: QTBUG-121787 Change-Id: I76eedfb6b15c4091f726a5652e3530001d7cdaf7 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Doc: Fix readString() and readByteArray() code snippetsAndreas Eliasson2024-02-151-4/+4
| | | | | | | | | | | Both of these functions return a StringResult, which has no StringResult::code member. Instead, use the existing StringResult::status member. Fixes: QTBUG-122254 Pick-to: 6.7 6.6 6.5 6.2 Change-Id: I0b9bfa1fc9a30e9c542ab90f3d8f4243bdeda762 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* QFileInfo: clarify the docs with respect to "file" == file system entryAhmad Samir2024-02-021-0/+18
| | | | | | | | | | | | | The word "file" could be slightly misleading in this context, because it refers to an entry on the file system, which could be a regular file, a dir, a special character device. Clarify the meaning by using "file system entry" instead of just "file". Fixes: QTBUG-120688 Pick-to: 6.7 6.6 6.5 Change-Id: Ic2a91cc74336a6718c13ad1ffd9f2c4001e5d63f Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Change license of .qdoc filesLucie Gérard2024-02-012-2/+2
| | | | | | | | | | | According to QUIP-18 [1], all .qdoc files should be LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only [1]: https://contribute.qt-project.org/quips/18 Pick-to: 6.7 Change-Id: I4559af21fc9069efa9bf0cbd29c5e86cfdac9082 Reviewed-by: Kai Köhne <kai.koehne@qt.io>
* QFileInfo: cleanup snippets fileAhmad Samir2024-01-221-10/+33
| | | | | | | | This makes it possible for LSP clients, e.g. clangd, to inspect the code while typing it, which hopefully means less errors. Change-Id: Ib2ed8fec94a559575237107afbcd2bdb3c46ef8d Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* qt6_wrap_cpp: Add .moc generationOrkun Tokdemir2024-01-192-0/+21
| | | | | | | | | | | | | | | | | | | | | | | | When a `.moc` file is included in a source file and that source passed to `qt_wrap_cpp`, Users should add the generated `.moc`s path to the target's include path. Since we don't share anything about the output path of generated files by `qt_wrap_cpp`, it makes sense to add in inside `qt_wrap_cpp`. And also, the generated `.moc` file is added to target's source to complete the dependency graph. Otherwise, Users need to get output variable and pass it to target's sources. * Update docs * Add test [ChangeLog][Build System] qt_wrap_cpp will accept .cpp files from now on. When .cpp a file is passed to qt_wrap_cpp, TARGET parameter becomes required. Generated .moc files are added to target's sources inside qt_wrap_cpp. That's why the output parameter will not contain generated .moc files. Fixes: QTBUG-113402 Change-Id: I54dd2b1ff8e5c9ba457b1eb4f73b0a8190d9c659 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io> Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
* Remove foreach snippets from the documentationKai Köhne2024-01-161-6/+0
| | | | | | | | | | | | | | | We don't recommend foreach anymore, and have in fact adapted two snippets already to use for(), but missed the documentation text. In any case, it feels a bit weird to give an example how to iterate over QStringList in each of these methods, so we might as well just remove this part. Pick-to: 6.6 6.7 Change-Id: If8744e48961661ad518f5f24781c38f371d981bc Reviewed-by: Jaishree Vyas <jaishree.vyas@qt.io> Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
* QUrlQuery/Doc: fix resulting query with ( and ) delimitersThiago Macieira2024-01-121-1/+1
| | | | | | | | There's no final ) because there's nothing there to be delimited. Pick-to: 6.5 6.6 6.7 Change-Id: I6e2677aad2ab45759db2fffd17a4ce4aa902e140 Reviewed-by: David Faure <david.faure@kdab.com>
* Doc: Use Qml DefaultProperty as example for Q_CLASSINFOKai Köhne2023-12-201-1/+1
| | | | | | | | | | | Setting a DefaultProperty is arguably something more useful to people than the 'made up' version example. Also add more links to the relevant QML pages. Pick-to: 6.6 6.7 Change-Id: Id967df7ddf81511299f95b9fd24f56af671fb855 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Replace QPair with std::pair in the docsMarc Mutz2023-12-131-1/+1
| | | | | | | | | | | | | QPair _is_ std::pair. It's confusing that debuggers consistently show the real name, std::pair, while the API and docs continue to maintain the illusion that there is such a thing as QPair. Use std::pair everywhere. Pick-to: 6.7 6.6 6.5 Task-number: QTBUG-115841 Change-Id: I009e2fc415a79a74b583a13cf11e4ff9483a7f6b Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
* Doc: QIdentityProxyModel::itemData() should be reimplemented tooDavid Faure2023-12-111-1/+7
| | | | | | | | | | | | | | | | This is a "regression" (voluntary, known) from commit c27d2a57a441f9a1ce760e71635bd4c96882249d which changed QAbstractProxyModel::itemData() to call the source model's itemData(), so our data() reimplementation is no longer used. Of course this only matters if itemData() is actually called, which isn't the case in Qt itself. People will likely skip this if they don't care - but if itemData() is used in the project, then this shows how to reimplement it correctly. Pick-to: 6.7 6.6 Change-Id: I3acea16c05d30d7526bac32fd6cce42b5ad4b617 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* QObject: allow calling findChild() without a nameRym Bouabid2023-11-221-1/+1
| | | | | | | | | | | Add an overload of findChild() without a name argument to be able to call the function with options value only. [ChangeLog][QtCore][QObject] Added findChild() overload taking no name. Task-number: QTBUG-103986 Change-Id: Id06b6041408fcf4cc1eeba975afce03f3a28f858 Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* QStringList: add filter(QStringMatcher) overloadAhmad Samir2023-10-221-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Now that users can pass a QStringMatcher to do the matching, change the existing overload to not use QStringMatcher. Thanks to Giuseppe D'Angelo for the idea of passing a QStringMatcher to filter instead of using a magic number to decide whether to use QStringMatcher or not. Results of running filter() and filter_stringMatcher, times are in msecs and this was compiled with gcc -O3: Without With QStringMatcher list10 0.00022 0.000089 list20 0.00040 0.00014 list30 0.00058 0.00018 list40 0.000770 0.00023 list50 0.00094 0.00027 list70 0.0012 0.00037 list80 0.0014 0.00041 list100 0.0018 0.00050 list300 0.0054 0.0014 list500 0.0091 0.0023 list700 0.012 0.0032 list900 0.016 0.0041 list10000 0.17 0.045 Drive-by change: optimize tst_QStringList::populateList(). [ChangeLog][QtCore][QStringList] Added filter(const QStringMatcher &) overload, which may be faster for large lists and/or lists with very long strings. [ChangeLog][Possible Performance Changes][QtCore][QStringList] Changed the implementation of filter(QStringView) overload to not use QStringMatcher by default. Using QStringMatcher adds overhead, so it is beneficial/faster when searching for a pattern in large lists and/or lists with long strings, otherwise using plain string comparison is faster. If using QStringMatcher makes a difference in your code, you can use the newly added filter(QStringMatcher) overload. Change-Id: I7bb1262706d673f0ce0d9b7699f03c995ce28677 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* doc: improve property example slotSamuel Gaist2023-10-141-0/+3
| | | | | | | | | | | The current example shows a minimal implementation. However, neither this example nor the documentation explains what happens without the guard. Although it's not mandatory, the large majority of the time it's a good practice to have it. This patch improves this part. Change-Id: I411a9d66bd7d8ba16aac87e28b5cab219fd71a5d Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Paul Wicking <paul.wicking@qt.io>
* Doc: Improve documentation for qInstallMessageHandler()Kai Köhne2023-10-131-23/+12
| | | | | | | | | | | | | | | | | | Mention that QtMessageHandler needs to be reentrant, as well as other caveats. Mention QLoggingCategory, so people do know that they don't have to necessarily implement their own handler to filter messages (and that not all messages reach the handler). Also mention qFormatLogMessage(). Finally, give a more useful example for a custom message handler that logs to a file. Note that the example leaks a file handle at exit, but that is arguably not that bad. Pick-to: 6.5 6.6 Change-Id: I5be44167b266c9bbdbb0e94806bb024c9b352a32 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QStringConverter: clarify decode()/encode() API docsAhmad Samir2023-10-061-0/+24
| | | | | | | | | | | These methods return a struct which is implicitly convertible to QString/QByteArray respectively. Don't hide the return type from QDoc, this simplifies telling users what those methods return exactly. Fixes: QTBUG-117705 Pick-to: 6.6 6.5 Change-Id: Ibb22a1e54fffce8f5f20aaabe47983870ccfba1e Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Remove Custom Type Example and Custom Type Sending ExampleRym Bouabid2023-10-041-0/+90
| | | | | | | | | | | | | | | | | | | | | 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>
* QSignalMapper: Fix compile error in snippetsTasuku Suzuki2023-09-261-1/+1
| | | | | | | Change-Id: I676cf8e120aedddc2565d2b08dae3f5ec612c1ec Pick-to: 6.6 Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* QDataStream: Documentation fixChristian Ehrlicher2023-09-251-4/+4
| | | | | | | Fix the code snippets to match the Qt coding style. Change-Id: Id65d2253e620d217fa3ada7b82e28f4939336543 Reviewed-by: Paul Wicking <paul.wicking@qt.io>
* Un-deprecate qSwap()Marc Mutz2023-09-221-9/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | It seems to have fallen prey to the mass-deprecation of <QtAlgorithms> in Qt 5.2. Since it didn't actually duplicate STL functionality, that was uncalled-for: Unlike std::swap(), it's ADL-enabled, so the docs were wrong to suggest replacing it with std::swap instead. In fact, the tony-table that 5957f245c6c77c98d7e90d614c9fe2cdbfe7e8e6 added to qalgorithms.qdoc didn't include qSwap(), yet, qSwap() was marked as deprecated. Un-deprecate and expand the discussion to more faithfully represent its value, without going into the depths of teaching how to swap correctly in C++ (link to boost.org and cppreference.com for that instead). Remove the example that used qSwap() on doubles, which is precisely _not_ how you should use it. Amends 5957f245c6c77c98d7e90d614c9fe2cdbfe7e8e6(!). [ChangeLog][QtCore] Un-deprecated qSwap(). Pick-to: 6.6 6.5 6.2 5.15 Change-Id: I4981005ba71b0d1824f2a46897145255fa66a7ea Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
* Add static constexpr Boyer-Moore Latin-1 string matcherØystein Heskestad2023-09-071-0/+8
| | | | | | | | | | | | | | | | | | | | QStaticLatin1StringMatcher is a static templated Latin-1 Boyer-Moore string matcher which can be case sensitive or not. It should be used when the needle is known at compile time so there is no run-time overhead when generating the skip table. The convenience functions qMakeStaticCaseSensitiveLatin1StringMatcher and qMakeStaticCaseInsensitiveLatin1StringMatcher should be used to construct the matcher objects. Green Hills Optimizing Compilers are currently not supported. [ChangeLog][QtCore] Added QStaticLatin1StringMatcher, which can be used to create a static constexpr string matcher for Latin-1 content. Task-number: QTBUG-100236 Change-Id: I8b8eed1e88e152f29cbf8d36d83e410fafc5ca2c Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Mark all of Qt as free of Q_FOREACH, except where it isn'tMarc Mutz2023-08-196-0/+12
| | | | | | | | | | | | | | | | | | | | | | The density of Q_FOREACH uses in this and some other modules is still extremely high, too high for anyone to tackle in a short amount of time. Even if they're not concentrated in just a few TUs, we need to make progress on a global QT_NO_FOREACH default, so grab the nettle and stick to our strategy: Mark the whole of Qt with QT_NO_FOREACH, to prevent new uses from creeping in, and whitelist the affected TUs by #undef'ing QT_NO_FOREACH locally, at the top of each file. For TUs that are part of a larger executable, this requires these files to be compiled separately, so add them to NO_PCH_SOURCES (which implies NO_UNITY_BUILD_SOURCES, too). In tst_qglobal.cpp and tst_qcollections.cpp change the comment on the #undef QT_NO_FOREACH to indicate that these actually test the macro. Task-number: QTBUG-115839 Change-Id: Iecc444eb7d43d7e4d037f6e155abe0e14a00a5d6 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* _qt_internal_create_moc_command: Fix genex parseOrkun Tokdemir2023-08-171-2/+23
| | | | | | | | | The function was replacing the `>` character in generator expressions coming from `add_compile_definitions`. This was creating generator expression syntax errors. Discard generator expressions from character replacing. Add tests for the three cases. Fixes: QTBUG-111717 Change-Id: I694d2908738085fdf15112834f20183a9f393422 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
* Modernize snippetFabian Kosmale2023-08-141-4/+4
| | | | | | | | It referenced QDeclarativeComponent, which has been gone for a very long time. Also replace the foreach with a proper for loop. Change-Id: I7f30ca10a235137dbdf34b7684e2c38610242b17 Reviewed-by: Andreas Eliasson <andreas.eliasson@qt.io>
* QString docs: miscellanea improvements around string constructionGiuseppe D'Angelo2023-07-071-3/+3
| | | | | | | | | | * Correct the semantics of the QString(const char *) constructor * Mention operator"" * Get rid of QLatin1StringView * Improve QStringBuilder docs Change-Id: I80a0833a6d31fae1b05ee49bdb9d2dc6baf84cf0 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Doc: Fix documentation issuesTopi Reinio2023-06-091-2/+2
| | | | | | | | | | | | | | | | The Qt Widgets Application example was moved to manual tests, and no longer contains the snippet identifiers. Fix \snippet and \quotefile commands to quote similar code snippets from other examples or snippet files. Fix also the following documentation warnings: * No such parameter 'parsingMode' in QUrl::fromEncoded() * Missing image: rsslisting.cpp Pick-to: 6.6 6.5 Change-Id: Ibc989e83abc49837db08628facaf8e5f72b2f123 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* Fix some syntax errors in snippetsSzabolcs David2023-06-083-3/+3
| | | | | | | | | | | | - The following error occurs when trying to use these example codes: "error: expected primary-expression before ‘!=’ token" - Rename "map" to "hash" in the QHash snippet Amends 7d542e1daf09caadf6d3e36c4b09bdf94952c5a1. Pick-to: 6.6 6.5 Change-Id: I1ad5b799f444bf074dbfb44223c00770ecf456c7 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* QFuture: Gracefully handle a destroyed context in continuationsArno Rehn2023-05-301-0/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch relaxes the requirements on the context object of continuations. Instead of having to stay alive during execution of the whole chain, it now only has to stay alive during setup of the chain. If the context object is destroyed before the chain finishes, the respective future is canceled. This patch works by using QFutureCallOutInterface and signals instead of direct invocation of the continuation by the parent future, similar to how QFutureWatcher is implemented. If a continuation is used with a context object, a QBasicFutureWatcher is connected to the QFuture via a QFutureCallOutInterface. When the future finishes, QBasicFutureWatcher::finished() triggers the continuation with a signal/slot connection. This way, we require the context object to stay alive only during setup; the required synchronization is guaranteed by the existing event and signal-slot mechanisms. The continuation itself does not need to know about the context object anymore. [ChangeLog][QtCore][QFuture] Added support for context objects of continuations being destroyed before the continuation finishes. In these cases the future is cancelled immediately. Fixes: QTBUG-112958 Change-Id: Ie0ef3470b2a0ccfa789d2ae7604b92e509c14591 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Doc: fix warnings for QSetIterator see-alsosVolker Hilsheimer2023-05-251-9/+0
| | | | | | | | | | | | Amends 0306247f5a5d057fedfa183da06a78cc41139d1d, which removed some APIs from QSetIterator as they couldn't be implemented without operator--. That resulted in qdoc warnings, which this patch removes by splitting the QSetIterator documentation into a separate block that quotes the previously shared documentation text, but uses a reduced set of see-also links. Change-Id: I2aac59b927a36216a718aa8e5d092ea4d9f6c15b Reviewed-by: Topi Reiniö <topi.reinio@qt.io>
* QSemaphore: add QDeadlineTimer APIThiago Macieira2023-05-161-0/+6
| | | | | | | | This removes the last use of QtPrivate::convertToMilliseconds(). Change-Id: I6f518d59e63249ddbf43fffd1759fee2e00d36f4 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
* Brush up the container code snippetsFriedemann Kleint2023-05-0411-110/+84
| | | | | | | | | | | | | | | | | | | | - Bring iterator loops into a consistent form using auto and creating and end variable, use cbegin()/cend() where suitable - Use (std::)endl instead of Qt::endl for iostreams - Fix removed container conversion API (QList::fromSet, QSet::toList()) - Use range-based for instead of foreach - Use initializer lists - Use qPrintable(QString) for output to std::ostream - Use qsizetype - Remove some unused snippets Complements f6b137bdc43d4021cbbe602759dbcced2e04d638. Pick-to: 6.5 Change-Id: I8a167099cdb224f45b984fa834d46269144a7ef0 Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de> Reviewed-by: Ahmad Samir <a.samirh78@gmail.com> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* Doc: Use qt_add_executable() not add_executable() in snippetsLeena Miettinen2023-04-261-5/+5
| | | | | | | | | Changes code snippets that are visible in the docs. Task-number: QTBUG-113116 Pick-to: 6.5 Change-Id: If743234bfe6947acf02307bf1144daad4fba5d73 Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
* Remove unused documentation code snippetsFriedemann Kleint2023-04-1723-523/+3
| | | | | | | | | | | | | | | | | | | Modules: - Core - Gui - Widgets - Open(Widgets) - PrintSupport - Sql - Network - Concurrent - Testlib Pick-to: 6.5 Change-Id: I63e58c01bec4bd162486020f0085227fdaa83b18 Reviewed-by: Ahmad Samir <a.samirh78@gmail.com> Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* Fix qdoc warning about missing QMultiMap code snippetFriedemann Kleint2023-04-061-13/+4
| | | | | | | | | | | | | | | | | | | Bring back missing code snippet src_corelib_tools_qmultimap.cpp#19, fixing: qtbase/src/corelib/tools/qmultimap.qdoc:1007 Command '\snippet (//! [19])' failed at end of file 'qtbase/src/corelib/doc/snippets/code/src_corelib_tools_qmultimap.cpp' As a drive-by, use a more modern form, avoiding repeated invocation of end(). Amends 3236b64db8bb26a6c1c2c288cb47ecc08a7d526f. Task-number: QTBUG-105109 Pick-to: 6.5 6.2 Change-Id: I09635eedd773ed16517773a9bf282b0386beba26 Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* Long live QtFuture::makeReadyVoidFuture() and QtFuture::makeReadyValueFuture()Ivan Solovev2023-04-051-3/+17
| | | | | | | | | | | | | | | | [ChangeLog][QtCore][QFuture] Added QtFuture::makeReadyVoidFuture() and QtFuture::makeReadyValueFuture(). Basically, these methods behave like QtFuture::makeReadyFuture(), but QtFuture::makeReadyValueFuture() does not have a "const QList<T> &" specialization returning QFuture<T> instead of QFuture<QList<T>>, which allows it to always behave consistently. This patch also introduces usage of the new methods around qtbase. Task-number: QTBUG-109677 Change-Id: I89df8b26d82c192baad69efb5df517a8b182995f Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* Long live QtFuture::makeReadyRangeFuture()Ivan Solovev2023-04-051-0/+14
| | | | | | | | | | | | | | | | [ChangeLog][QtCore][QFuture] Introduce QtFuture::makeReadyRangeFuture(). This method takes a container which has input iterators and returns a multi-value QFuture<ValueType>, where ValueType is the underlying type of the input container. This commit also replaces the usage of buggy QtFuture::makeReadyFuture(const QList<T> &) overload with the new method. Task-number: QTBUG-109677 Change-Id: I019e62eac74c643d88a65b3cc0085bc7c33bc712 Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* QtBase/doc: fix examples for QHash/QMap/QMultiMap::erase()Christian Ehrlicher2023-03-313-84/+32
| | | | | | | | | | | | | QHash/MultiHash & QMap/MultiMap::erase() do no longer take an iterator in Qt6. Clean up the examples by only providing one example, the rest is common c++ which should not be handled in the Qt documentation. Also mention erase_if() and remove references to the (soon to be deprecated) Java-style iterators. Pick-to: 6.5 6.2 Fixes: QTBUG-105109 Change-Id: I47b11f3b5dcc173494e5c6f9ad0167c613b12209 Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* QFutureInterface: add a warning when an existing continuation is overwrittenIvan Solovev2023-03-281-0/+14
| | | | | | | | | ... and also extend the documentation to explain this case explicitly. Fixes: QTBUG-107545 Pick-to: 6.5 6.2 Change-Id: I9414cc677b037989de60e97871485018e5c8a569 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Corelib: s/Q_OS_MAC/Q_OS_DARWIN/wg except for doc and definitionEdward Welbourne2023-03-201-1/+1
| | | | | | | | | | I got tired of being told off by the inanity 'bot for faithfully reflecting existing #if-ery in new #if-ery. Retain only the documentation and definition of the deprecated define. Change-Id: I47f47b76bd239a360f27ae5afe593dfad8746538 Reviewed-by: Ahmad Samir <a.samirh78@gmail.com> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>