summaryrefslogtreecommitdiff
path: root/examples/corelib
Commit message (Collapse)AuthorAgeFilesLines
* RSS listing example: prefer setDevice() over addData(readAll())Edward Welbourne2023-05-161-13/+9
| | | | | | | | | | | | | | | The network reply is a QIODevice, so the QXmlStreamReader can be set to read from it directly, which it might potentially do incrementally, rather than by reading all the data in one go. In the process, change the set-up of the reply to first check that it got a valid URL, then check it got a reply, before doing things with that reply. Pick-to: 6.5 Task-number: QTBUG-111228 Change-Id: I3642e24e0d10721e4a0325b35a94dcb5dfbcd4e6 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Shrink the CBOR dumper example's imageEdward Welbourne2023-05-151-0/+0
| | | | | | | Apply optipng -o7 -zm9 -strip all to the image to make it more compact. Change-Id: Iebfc1f767759b5beac47bd7efa61d1c655163f03 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* rsslisting example: fix bug in construction of title stringEdward Welbourne2023-05-151-4/+3
| | | | | | | | | | | | | | | | | | The correct time to clear titleString and linkString is at the start of the item element, to avoid not only the left-overs from a previous item but also any stray titles and links that don't belong to any item. The channel element, that contains the items, may also have title and link elements. This, indeed, lead to the first entry in the displayed table having a "Qt Blog" prefix on its blog-post's title. Fortunately the link was already being set, usually to empty, due to the lack of rss:about attributes on item elements. Pick-to: 6.5 Task-number: QTBUG-111228 Change-Id: I16647e2498b58caaafa6e88ef73f0d934a1f8396 Reviewed-by: Alex Blasche <alexander.blasche@qt.io> Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* rsslisting example: shuffle parts of constructor for clarityEdward Welbourne2023-05-151-8/+4
| | | | | | | | | | Group related things together, improve the logical flow of the code. Pick-to: 6.5 Task-number: QTBUG-111228 Change-Id: If3eb577b74128b305ca5fb3074168280ec2d4db8 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* rsslisting example: move default URL to main()Edward Welbourne2023-05-153-4/+5
| | | | | | | | | | | | | It felt more natural that the RSSListing class would be agnostic about the default URL, so let it be a constructor parameter. In the process, update the URL to what the old one now redirects to (thanks to Ivan Solovev for spotting that) and make the constructor explcit (thaks to Ievgenii Meshcheriakov for suggesting this). Task-number: QTBUG-111228 Pick-to: 6.5 Change-Id: I9f4c0d126e0872bb4ec6e6bb41add7e9d2a9537f Reviewed-by: Ievgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io>
* rsslisting example: Tidy up #include usageEdward Welbourne2023-05-153-7/+4
| | | | | | | | | | | | | | | | Replace one #include with a forward-declaration - in rsslisting.h QUrl is only passed by reference to a function. Shuffle order of existing forward declarations to be alphabetic, in the process. Shuffle #include order in sources so that this example's own headers appear before the Qt ones. Pick-to: 6.5 Task-number: QTBUG-111228 Change-Id: I69a9e091c77f9d3190c0217c8bd9262e056f66fc Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
* rsslisting example (coding style): split a long line, purge stray bracesEdward Welbourne2023-05-151-5/+4
| | | | | | | Pick-to: 6.5 Task-number: QTBUG-111228 Change-Id: Ic919d4dee74823f11c55d286beba447d45111754 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* rsslisting example (coding style): fix horizontal spacingEdward Welbourne2023-05-152-3/+3
| | | | | | | | | | Remove space after *, insert space after comma. Pick-to: 6.5 Task-number: QTBUG-111228 Change-Id: I7525715dede20b45241efaf3f9540c896b1455c7 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Konrad Kujawa <konrad.kujawa@qt.io>
* rsslisting example: remove unused include and surplus blank linesEdward Welbourne2023-05-152-7/+0
| | | | | | | | Pick-to: 6.5 Task-number: QTBUG-111228 Change-Id: Ibfa82aef67eaf6ba758dade30a4c9542f2836123 Reviewed-by: Mate Barany <mate.barany@qt.io> Reviewed-by: Ievgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io>
* savegame example: clarify that CBOR can be readEdward Welbourne2023-05-151-5/+6
| | | | | | | | | | | | | The documentation talked about using CBOR to keep folk from reading, where (of course) it merely makes it more obscure (and compact). Make clear that this just makes it less easy and mention the tool that makes it easy again. Task-number: QTBUG-111228 Pick-to: 6.5 Change-Id: I472acda4b7533db41ab0e78b694e0256b34d2b40 Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Add metadata to serialization examplesEdward Welbourne2023-05-153-0/+4
| | | | | | | | | | | | | | There's no separate category for {de,}serialization, so I've put them in Input/Output; and at least some of them are relevant to transmission over the network, so include that as a tag, so that someone writing a network application that wants to use what they illustrate gets a chance of being lead to it. Pick-to: 6.5 Task-number: QTBUG-111228 Change-Id: Ie9f6dbaf85aed852e9f64eba05ec8c5fe0a7382d Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* rsslisting example: don't leak the RSSListing objectEdward Welbourne2023-05-091-2/+2
| | | | | | | | | | | It was new'd and unparented, so its destructor was never getting called. A stack instance will do just fine. Pick-to: 6.5 Task-number: QTBUG-111228 Change-Id: If362b0e1e5b50d711a8fe8e01a8830034edf5363 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Dennis Oberst <dennis.oberst@qt.io>
* Update cbordump image to a higher-resolution oneEdward Welbourne2023-05-091-0/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Incidentally using reversed video, too, as that's what came naturally to the terminal I was using. File is smaller, but text in the new image is considerably more readable and the image is bigger. The examples guideline calls for an image giving some idea what the example is about, with a 4:3 or 5:4 aspect ratio. An image shorter than its width wasn't practical, and getting a useful amount of information in a height less than 3/2 of the width would have required widening into blank space purely to satisfy the aspect ratio. The prior image's ratio was about 12:7, the new one's is roughly 2:3. The old image showed the start of cbordump -a output, which is rather less illuminating than the default output of formatted data; it's also rather verbose, so was cut off part way through. It does, however, illustrate how the annotated form might be useful for debug purposes. The image also had a lot of blank space to the right of the text of interest, wasting roughly half of its width; it could easily have been cropped to 1:1 without loss of information. As example data-set, it used ../savegame/save.dat, but without any hint to how to generate that. I decided to include a hint to how to generate a CBOR data file to dump, then show the standard output and only the beginnings of the annotated output, as the latter (even on its own) would make the aspect ratio considerably taller. In the context of the standard display, the preamble of the annotated one gives a reasonable feel for what's going on, without belabouring the point. Pick-to: 6.5 Task-number: QTBUG-111228 Change-Id: Ic54893c483607e95627a50db76a0d9918744c07e Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Doc: Add XML, Json, CBOR examples to IO categoryKai Köhne2023-05-094-0/+4
| | | | | | | | Pick-to: 6.5 6.5.1 Task-number: QTBUG-112372 Change-Id: I867bd33ff08629e03b35eccd4b7418573abe7c68 Reviewed-by: Øystein Heskestad <oystein.heskestad@qt.io> Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
* savegame ex.: revamp the way print() worksMarc Mutz2023-05-098-20/+29
| | | | | | | | | | | | | | | Basically, instead of re-creating QTextStreams all the time, create it once, in main(), and then pass it to print() alongside the int indentation. Also fix a hard-coded indentation value that should have been relative to the caller's indentation level. Pick-to: 6.5 6.2 Task-number: QTBUG-108857 Change-Id: I811447295c9c3fdef23f61aff31ebe82941eb3b4 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Flip string comparisons in savegame exampleEdward Welbourne2023-05-041-2/+2
| | | | | | | | | | | | | | This follows up to commit 9834e80833783357743b2a5abe3071760638effb, fixing an accidental flip to the meaning of keywords on the command-line. If the first word is "load" we should load a prior game, not start a new one; if the second is "binary" we should use CBOR, the binary format, not JSON. Pick-to: 6.5 Task-number: QTBUG-111228 Change-Id: If29070777daf68f2f959bc1ec4ffd67ba90b28ba Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* savegame ex.: revamp the way we (de)serialize JSONMarc Mutz2023-05-037-113/+166
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | JSON, unlike, say, QDataStream, allows building up objects independent of some central object, and combining them into a QJsonDocument later. This suggests returning QJsonObjects from a toJson() const method instead of having the caller supply a QJsonObject. Doing it this way enables transparent move semantics to kick in, too. For deserialization, use a fromJson() named constructor for value-like classes (where identity doesn't matter, only equality). Keep using read(), too, and add a note to explain when to use which form. Also, avoid the triple lookup from if (json.contains("key") && json["key"].isSoughtType()) mFoo = json["key"].toSoughtType(); by using C++17 if-with-initializer and showing the trick with Undefined never being of isSoughtType(): if (const QJsonValue v = json["key"]; v.isSoughtType()) mFoo = v.toSoughtType(); Adjust the discussion to match the new code, up the copyright years and rename some qdoc snippet markers from nondescript [0]/[1] to [toJson]/[fromJson]. Task-number: QTBUG-108857 Pick-to: 6.5 6.4 6.2 Change-Id: Icaa14acc7464fef00a59534679d710252e921383 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Replace runic XSLT with a python script and tidy cbordump codeEdward Welbourne2023-05-023-201/+276
| | | | | | | | | | | | | | | Filters records on having value < 256, or an RFC, previously hacked into the XSLT to produce the last update, with a bit of hand-editing. Using a python script makes it easier to control the formatting and other details; for example, severl entries previously had descriptions that mentioned their RFC, with specific section, to which the XSLT was adding a redundant mention of the RFC. It is also possible to exploit C++ string juxtaposition to get tidily-presented string literals, without having to resort to raw strings. Task-number: QTBUG-111228 Change-Id: Ibd1c93dc1c88689e78b2b13a6bcb59a003f4df0f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Doc: Add 'Mobile' category to Qt Android Notifier exampleTopi Reinio2023-05-021-0/+1
| | | | | | | | | | The example demonstrates accessing native Android APIs in Qt applications, tag it with 'Mobile' category. Pick-to: 6.5 Task-number: QTBUG-112378 Change-Id: I5f936409aafb22175eab59fdb210ecd03fecb1f3 Reviewed-by: Kai Köhne <kai.koehne@qt.io>
* Android-example: add missing properties in AndroidManifest.xmlBartlomiej Moskal2023-04-261-2/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | After changing android target SDK version to 31, some missing values has to be defined in AndroidManifest.xml. AndroidManifest.xml template was updated in qtbase in: 56dee3de5e4ac1c4d37a2c5e27361e7ddbdea1a7 commit. In case when example uses its own AndroidManifest.xml file, it need to be updated separately. * android:exported="true": because the manifest sets an intent-filter, and it then has to explicitly to avoid the warning [1]. * android:allowBackup="true": this has to be explicitly set, we set it to the default value here [2]. * android:fullBackupOnly="false": SDK 23+ use this to deteremine to user auto backup or not, we set it to the default value here [3]. [1] https://developer.android.com/guide/topics/manifest/activity- element#exported [2] https://developer.android.com/guide/topics/manifest/application- element#allowbackup [3] https://developer.android.com/guide/topics/manifest/application- element#fullBackupOnly Fixes: QTBUG-112816 Pick-to: 6.5 6.2 5.15 Change-Id: Ia48007a84009901be508d6cc087790d574227ad7 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io> Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Update table of CBOR tag descriptions in cbordump exampleEdward Welbourne2023-04-192-46/+185
| | | | | | | | | | | | | | | | | | | | A comment said how to do this, so I gave it a try. Added a note to the instructions to save the next person to look at this from, as I initially did, thinking the comment in the generated code had the URL wrong. It turns out that some of the newer additions to the IANA registry have semantics elements that spread across several lines. I don't know the XSLT magic to replace each newline in a value, along with its preceding and following spacs, by a single space, so adapted the XSLT to produce C++ raw strings to wrap these multi-line entries. That'll produce somewhat ugly output, so left a TODO for the better solution. Task-number: QTBUG-111228 Pick-to: 6.5 Change-Id: I7d5e968284e0f1da2ec990af9512c9b7cb886792 Reviewed-by: Mikołaj Boc <Mikolaj.Boc@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Remove excess namespaces from XSLTEdward Welbourne2023-04-191-1/+2
| | | | | | | | In the process, break up a long line. Change-Id: Iec50e3bf292da9a3d4aef22bf5c59f2008b35c1f Reviewed-by: Mikołaj Boc <Mikolaj.Boc@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* savegame ex.: give some TLC to main()Marc Mutz2023-04-111-8/+11
| | | | | | | | | | | | | | - include what you use - make 'args' const, so we don't detach in op[] - make boolean variables const - use QString::compare(lhs, rhs, Qt::CaseInsensitive) instead of lhs.toLower() == rhs - use new _L1 UDL - fix indentation of a return statement Pick-to: 6.5 Change-Id: If9da4fbe975d9a97939ea01558b2a8cef7ad3a24 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Move streambookmarks example into corelibe/serializationØystein Heskestad2023-03-3116-0/+769
| | | | | | | | | | | | The stream-based XML serialization API resides in corelib/serialization. Move the steambookmarks example there. The Qt XML documentation is updated to no longer refer to this example code directly and refer to the direct location in the example documentation instead. Task-number: QTBUG-110647 Pick-to: 6.5 Change-Id: Id36fb04a6acb7b8d1eb008f61568fe0abc221e3d Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* Move rsslisting example into corelibe/serializationØystein Heskestad2023-03-217-0/+346
| | | | | | | | | | The implementation of the stream-based XML parser resides in coreslib/serialization. Moving the rsslisting example there. Task-number: QTBUG-110647 Pick-to: 6.5 Change-Id: I862909e767301250750b6ee0d8ac7e20d6bad2b1 Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* Rework documentation of cbordump exampleEdward Welbourne2023-03-201-23/+24
| | | | | | | | | | | | | | | Focus the phrasing on what it teaches - how to use the stream reader - more than the example application of that, displaying it. Update docs: * Changed name to conform to modern guidelines. * Consistently mark \c cbodrump as code. * Fix mentions of CborDumper and CborTagDescription to match code. * Say how the tagDescriptions table is used. Pick-to: 6.5 Task-number: QTBUG-111228 Change-Id: Ic12e77cf34caadc9f60527e886f94c76cb8cfeaf Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Use local names to make some numeric_limits references more readableEdward Welbourne2023-03-201-5/+7
| | | | | | | | Pick-to: 6.5 Task-number: QTBUG-111228 Change-Id: I220f5c2f13c8f01278be806c8e8d6a3a1be8e986 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Update the bindable properties exampleJames DeLisle2023-03-099-47/+43
| | | | | | | | | | | | - Fix the number of months in each duration - Move the user Country enum to use QLocale::Territory - Properly calculate the cost per month to match the UI label - Use QLocale to format the price display text - Fix some misspellings and grammar in the doc Pick-to: 6.2 6.5 Change-Id: I78a64f344073070cd94d5cb4a8a4c7c13afa337f Reviewed-by: Paul Wicking <paul.wicking@qt.io>
* Doc: fix links to renamed network examplesVolker Hilsheimer2023-03-011-1/+1
| | | | | | Pick-to: 6.5 Change-Id: I8790bb660070a092e268294b5640c6d5af41deb0 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Doc: Remove duplicate wordsAndreas Eliasson2023-02-281-1/+1
| | | | | | Change-Id: Ia7a38a1035bd34d00f20351a0adc3927e473b2e7 Pick-to: 6.5 6.4 6.2 Reviewed-by: Topi Reiniö <topi.reinio@qt.io>
* savegame ex.: fix include order [2/2]: game.hMarc Mutz2023-02-081-3/+3
| | | | | | | | | | | | | | Includes should be ordered from most specific to most general. This means that project-specific includes always come before Qt includes. This example didn't follow that guideline. Fix. Amends 88e8094f18e6581f2b652eb3d82f514ecf687046. Task-number: QTBUG-108857 Pick-to: 6.5 6.4 6.2 5.15 Change-Id: Iafdae9dd8e70ff99882c4344a023a21d15fa3c54 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* savegame ex.: make Level ctor explicitMarc Mutz2023-02-081-1/+1
| | | | | | | | | | A QString is not a full representation of a Level, so the Level(QString) ctor should be explicit. Pick-to: 6.5 6.4 6.2 5.15 Task-number: QTBUG-108857 Change-Id: I24b705139e61c4aaf59cb0aad3b536013e0d07df Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* savegame ex.: use ranged instead of indexed loopsMarc Mutz2023-02-082-4/+4
| | | | | | | | | Modernizes the code, and fixes qsizetype/int mismatch. Task-number: QTBUG-108857 Pick-to: 6.5 6.4 6.2 Change-Id: Id4262ee0bcb673d62135a81c30976903eef3e5e2 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* savegame ex.: use NSDMI, =default the default ctorMarc Mutz2023-02-082-6/+4
| | | | | | | | | Modernizes the code. Task-number: QTBUG-108857 Pick-to: 6.5 6.4 6.2 5.15 Change-Id: I6ddf1de3699506ffc0fc4b1034ab48defafcf174 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* savegame ex.: fix include orderMarc Mutz2023-02-082-3/+4
| | | | | | | | | | | | Includes should be ordered from most specific to most general. This means that project-specific includes always come before Qt includes. This example didn't follow that guideline. Fix. Task-number: QTBUG-108857 Pick-to: 6.5 6.4 6.2 5.15 Change-Id: I42727ff8bdef5336368cde349cbcb8d10bb6289f Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* savegame ex.: fix extra ';' after Q_GADGETMarc Mutz2023-02-081-1/+1
| | | | | | | | | | | Fixes compiler warnings. Amends 1ff52e478bab33f3aaba5ec185295411a0e6867d. Task-number: QTBUG-108857 Pick-to: 6.5 6.4 6.2 5.15 Change-Id: Id8b81c67e55baf490aabd0483b5800b3e61965ee Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* permissions: Replace deprecated location permission usage keyTor Arne Vestbø2023-02-081-5/+5
| | | | | | | | | And add the macOS specific key. Pick-to: 6.5 Change-Id: I1e0446a1927ef530322388417b9300ae287752c3 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
* Add android manifest and java files to exampleDavid Schulz2023-02-072-0/+3
| | | | | | | | | | These files should not change the outcome of the build process, but are merely added to better support the CMake and Android integration in Qt Creator. Also those files were previously listed in the OTHER_FILES section of the qmake project files. Change-Id: Id3d403130ee8800ed6b0877f9f1c3dd1f28b46b7 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* permissions: Set explicit bundle identifier for permissions exampleTor Arne Vestbø2023-02-071-0/+1
| | | | | | | | | | It's needed for location permissions to work. Pick-to: 6.5 Change-Id: Iffb5d92f863ab79434b4071d5896b349010f87fb Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io> Reviewed-by: Juha Vuolle <juha.vuolle@qt.io> Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
* permissions: Finalize permission example at end of CMakeLists.txtTor Arne Vestbø2023-02-011-2/+2
| | | | | | | | Otherwise the finalizers won't know which libraries we're linking to. Pick-to: 6.5 Change-Id: I886c46443b7289d6e2c7d824767ed5e34a0a1fbf Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
* Examples: Fix CMake Unity (Jumbo) buildsFriedemann Kleint2023-02-014-12/+14
| | | | | | | | | | Disambiguate variables and add some exclusions. Pick-to: 6.5 Task-number: QTBUG-109394 Change-Id: Ie72b3caab9fd571c3fb6f7d8606584885bc09e66 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Amir Masoud Abdol <amir.abdol@qt.io>
* permissions: Improve error when building example on non-supported platformTor Arne Vestbø2023-01-101-1/+4
| | | | | | | Pick-to: 6.5 Change-Id: I02f4fc087d49d21541b1e415db411c09db981278 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io> Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* Link update for Data Input Output in the save game exampleJaishree Vyas2023-01-051-1/+1
| | | | | | Pick-to: 6.4 6.5 Change-Id: I2a886766d59b9e75f42e401fca9c258fcbe02809 Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
* Doc: Fix broken linkAndreas Eliasson2023-01-021-5/+5
| | | | | | | | | | Also, adjust line length to be < 80 columns and make link parenthetical. Pick-to: 6.5 6.4 6.2 Fixes: QTBUG-107026 Change-Id: I5f7efa5d572103a6fb432d79a52a57363efd9dd7 Reviewed-by: Andreas Eliasson <andreas.eliasson@qt.io>
* Wait conditions example: fix an incorrect condition variable usageGiuseppe D'Angelo2022-12-282-15/+16
| | | | | | | | | | | | | | | | | | | | 3a449bbb69c9a3c3a5bc6a052f2de98ab79be7e9 amended the code to remove acquiring a lock when waking up a condition variable. It is fine to not have a lock associated when waking a condition variable; what I misunderstood was the scope of the lock, which (and this underlines the importance of commenting _what exactly_ a lock protects, for each and ever lock) protected both the buffer as well as the counter of the buffer. This made my reasoning flawed: it is necessary to keep the lock while notifying, otherwise the counterpart could verify the condition isn't satisfied and wait (e.g. see numUsedBytes==0), missing the wake from the other thread (which could arrive between the check and the wait). Amends the previous commit. Change-Id: If7db2d045331f1b33b976fb6bf6aa9117c41678f Pick-to: 5.15 6.2 6.4 6.5 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
* Remove useless Q_OBJECT in Semaphores exampleAleksandr Reviakin2022-12-071-3/+0
| | | | | | Fixes: QTBUG-108859 Change-Id: I1acf47b9dfd9c38546a2e965baa74067cedffc4a Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
* Wait conditions example: code tidiesGiuseppe D'Angelo2022-12-062-29/+38
| | | | | | | | | | | | | | | | | | | | | | | | | | | | In no particular order: * Clean up #includes. * Document what is protected by the mutex. * Use explicit, nullptr. * Use lock managers, not manual calls to lock/unlock. * Unlock the mutex before notifying the condition variables. * Condition variables are always meant to be used in a while loop, and never with a plain if, because of spurious wakeups. * Don't lock a mutex just to protect a plain integer. We have atomics for that use case. * Remove an unneeded signal, therefore also the need of using Q_OBJECT and the inclusion of the moc-generated file. Pick-to: 5.15 6.2 6.4 Fixes: QTBUG-108860 Change-Id: I2afc77955b95de8aa5fb88048cd9feb217f83b4f Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Use const reference in loop in JSON Save Game exampleAleksandr Reviakin2022-12-051-1/+1
| | | | | | Fixes: QTBUG-108857 Change-Id: I503a3c9ebe145d0dae52b74435212807405f0247 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* Examples: Use PRIVATE CMake linkageKai Köhne2022-11-3017-17/+17
| | | | | | | We (almost) only build apps, for which PRIVATE linkage makes more sense. Change-Id: I09a509c3fb33a00cdfdede687b3f95d638f42091 Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
* Examples: Use qt_standard_project_setup()Kai Köhne2022-11-1718-39/+36
| | | | | Change-Id: I0ceab08108b7e58e4e2ed25db9e3c289f5c0ddac Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>