Commit Graph

312 Commits

Author SHA1 Message Date
Mårten Nordheim
f3d2e2f555 Network chat: style fixes
The if statements were originally broken to fit 80-column width
but didn't have the braces we typically require.
It anyway fits inside our new 100-column width, so just do that.

Task-number: QTBUG-108873
Change-Id: Ib632f35607e6b716141c4c5d8211de7a0745c6ab
Reviewed-by: Konrad Kujawa <konrad.kujawa@qt.io>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
2023-05-31 12:56:00 +02:00
Mårten Nordheim
e33bbdb0ea Network chat: simplify lookup function
Task-number: QTBUG-108873
Change-Id: I3ca0c976236003c708130ed120dba14cfbbf8185
Reviewed-by: Konrad Kujawa <konrad.kujawa@qt.io>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
2023-05-31 12:55:59 +02:00
Mårten Nordheim
804b26b77d Network chat: when removing an entry in multihash, specify which one
Using only the key means all clients with that IP address are removed.
But there could be multiple clients running on the same multi-user
system.
So, use the value as well to remove just the specific one.

This also fixes a bug where, when a client disconnects, all of the
connections are removed from the client's map, but only _one_ is removed
from the GUI.

Task-number: QTBUG-108873
Change-Id: I87da862e8f337fd9c246ff5a2d243e514076fa5f
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Reviewed-by: Konrad Kujawa <konrad.kujawa@qt.io>
2023-05-31 12:55:58 +02:00
Mårten Nordheim
6eac22e2ca Network chat: avoid double lookups into hash
Task-number: QTBUG-108873
Change-Id: Iafa5a7a1ec99d2414f175f2d30fe03a90c6716f3
Reviewed-by: Konrad Kujawa <konrad.kujawa@qt.io>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
2023-05-31 12:55:57 +02:00
Mårten Nordheim
9db22a63a9 Network chat: Use QStringBuilder
It is a best practice after all

Task-number: QTBUG-108873
Change-Id: I11c23c080f6fe7f124e461affa88279d5def93f9
Reviewed-by: Konrad Kujawa <konrad.kujawa@qt.io>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
2023-05-31 12:55:56 +02:00
Mårten Nordheim
61afc6d109 Network chat: make ctors explicit
Task-number: QTBUG-108873
Change-Id: I08cd676aeb732d32b4d1e7d13a0aa1b37a46283f
Reviewed-by: Konrad Kujawa <konrad.kujawa@qt.io>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
2023-05-31 12:55:55 +02:00
Mårten Nordheim
3ece5e30b7 Network chat: default-initialize or direct-initialize members
Where possible

Task-number: QTBUG-108873
Change-Id: I8125ffd63cd0ad1970575fb1a6b85021c03c38d5
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Reviewed-by: Konrad Kujawa <konrad.kujawa@qt.io>
2023-05-31 12:55:54 +02:00
Mårten Nordheim
c437c33f29 Network chat: update includes
Prefer own headers, avoid full-module includes

Task-number: QTBUG-108873
Change-Id: I4282d4aab5fd66c64fc27cd130b223d33069d80f
Reviewed-by: Konrad Kujawa <konrad.kujawa@qt.io>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
2023-05-31 12:55:54 +02:00
Mårten Nordheim
1a55c8d887 Torrent example: update usage of integer types
Some of the 'int's are purposefully 32-bit because that's what the
protocol is, but others aren't. So, be more explicit.

Task-number: QTBUG-110622
Pick-to: 6.5
Change-Id: I338abca1f13b0c95f49a6f52933712f43f147590
Reviewed-by: Konrad Kujawa <konrad.kujawa@qt.io>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2023-04-11 18:25:42 +01:00
Topi Reinio
45ca5c8585 Doc: Use the \examplecategory macro to tag examples
The '\meta category' command was used for tagging examples with a
specific category, used in Qt Creators Welcome mode.

As we want to also generate lists of examples belonging to a category
elsewhere in the documentation, replace the command with a macro that
expands to the original \meta command and also adds the example to
a group using the \ingroup command. This way, the category names can
be used as arguments to the \generatelist or \annotatedlist commands.

Pick-to: 6.5
Task-number: QTBUG-112731
Change-Id: I46762dabc5f718fecc09a3533235eaa911dda5a0
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
2023-04-11 17:25:42 +00:00
Mårten Nordheim
826b606a5d Remove loopback network example
It doesn't showcase anything interesting that other examples
don't already show off.

Pick-to: 6.5
Change-Id: Ie95c3ddb3ff52b3beab54bd6fa75fb75ae5c7ba5
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Reviewed-by: Konrad Kujawa <konrad.kujawa@qt.io>
2023-03-23 16:02:28 +01:00
Mårten Nordheim
58dfb10781 Clean up multicast examples
They're small, not much to polish.

Pick-to: 6.5
Change-Id: Iada573504de557ab18381370bb9760b1f60cc2e4
Reviewed-by: Konrad Kujawa <konrad.kujawa@qt.io>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
2023-03-23 16:02:28 +01:00
Mårten Nordheim
bdcb0a32fa HTTP example: update screenshot
Fixes: QTBUG-108874
Pick-to: 6.5
Change-Id: Ib87895c6512abb967734ce4c1ed0be76c698feb4
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
2023-03-02 18:39:09 +01:00
Mårten Nordheim
277d809ba4 DNS Lookup: Use ideomatic cstdio include
Task-number: QTBUG-108873
Pick-to: 6.5
Change-Id: I646f0c985adc45a17103b5f98394f3def4b6ada2
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: Konrad Kujawa <konrad.kujawa@qt.io>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
2023-03-02 12:08:10 +01:00
Mårten Nordheim
af95f97466 DNS Lookup: Change local function to return struct instead of enum
This let's us get rid of an out-parameter.

Task-number: QTBUG-108873
Pick-to: 6.5
Change-Id: Ifc08d3905932f28ecdfdf3a7de1499700cc7e606
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2023-03-02 12:08:10 +01:00
Mårten Nordheim
83dac21813 DNS Lookup: Use standard functions to print version/help
showHelp was already in use, but not showVersion.
Return 0 in both cases, even if it's unreachable.

Task-number: QTBUG-108873
Pick-to: 6.5
Change-Id: Iba820e89d7de066130163e7829f75bbfcfa3f7dd
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2023-03-02 12:08:10 +01:00
Mårten Nordheim
a6dc860915 DNS Lookup: reflow some code to avoid exceeding column limit
Task-number: QTBUG-108873
Pick-to: 6.5
Change-Id: Ic17ded256152f7d89bd200ea0e163f2b8f1ea70a
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2023-03-02 12:08:10 +01:00
Mårten Nordheim
b300c6b777 DNS Lookup: Use std::optional instead of casting enum to int
Task-number: QTBUG-108873
Pick-to: 6.5
Change-Id: I0bd5dc004154c1c4026be2feb6187c53e5e77801
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2023-03-02 12:08:10 +01:00
Mårten Nordheim
5e16397a2c DNS Lookup: Avoid unneeded allocations in parsing function
By using .compare(~~~, Qt::CaseInsensitive) instead of .toLower()

Task-number: QTBUG-108873
Pick-to: 6.5
Change-Id: I60e1fdc0a54450e7385e90f84fd509e62b82d2c9
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Reviewed-by: Konrad Kujawa <konrad.kujawa@qt.io>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2023-03-02 12:08:09 +01:00
Mårten Nordheim
eb61d49ab3 Delete the Network Download (Manager)? examples
Their use of QtNetwork is already covered by the HTTP example.
While showcasing that QNAM easily deals with multiple simultaneous
requests, waiting until finished() is emitted to write anything is not
exactly idiomatic.
And managing your own queue to only have one request running at a time
is a weird example for an asynchronous framework.

In this regard, having an example for a complete download manager
(with a GUI) would be interesting, but may ultimately be very
time-consuming to make for limited gain.

Task-number: QTBUG-110643
Pick-to: 6.5
Change-Id: I6b2c1546b85fa89ab7ce1ff5565b0293b5710b74
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Reviewed-by: Ievgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io>
Reviewed-by: Konrad Kujawa <konrad.kujawa@qt.io>
2023-03-02 12:08:09 +01:00
Volker Hilsheimer
a02fb41c8e Doc: fix links to renamed network examples
Pick-to: 6.5
Change-Id: I8790bb660070a092e268294b5640c6d5af41deb0
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-03-01 19:14:39 +01:00
Mårten Nordheim
97dcf1ba18 Fortune* Example: update screenshots
Fixes: QTBUG-108875
Pick-to: 6.5
Change-Id: Ib57482959973815681b0b178acea3634a4f63220
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
2023-02-28 16:33:05 +01:00
Mårten Nordheim
32098963f2 Torrent example: Fix use-after-free crash
The crash would sometimes happen shortly after removing a torrent
since the RateController would still try to use it even though
it had been deallocated.

Pick-to: 6.5
Task-number: QTBUG-110622
Change-Id: Icad1531ea58560a3a3157a3ed8c0e6b283573196
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Reviewed-by: Konrad Kujawa <konrad.kujawa@qt.io>
2023-02-21 13:04:44 +01:00
Mårten Nordheim
f3de92cdad Torrent example: Fix some stack overflow issues
Because of the .size() used as part of the expression it
ends up copying sizeof(qsizetype) bytes to the array,
instead of the (rationally) expected 4 bytes.

Amends 69c31f6f68

Pick-to: 6.5
Task-number: QTBUG-110622
Change-Id: I732e3f4bb5934ff3860087baa91f9bebbf044a7f
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Reviewed-by: Konrad Kujawa <konrad.kujawa@qt.io>
2023-02-21 13:04:44 +01:00
Mårten Nordheim
d3c1445419 Torrent: simplify QBitArray usage
There is specific API for counting number of 0-bits

Pick-to: 6.5
Task-number: QTBUG-110622
Change-Id: Ifa33862ff7b98a59f362bc52c492e8a037799835
Reviewed-by: Konrad Kujawa <konrad.kujawa@qt.io>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
2023-02-21 13:04:44 +01:00
Tor Arne Vestbø
850ef55fc5 examples: Connect Quit action to QCoreApplication::quit, not QWidget::close
Pick-to: 6.5
Change-Id: I44ca7b61a4a261a7d3aad0dfeb870eb927ee768d
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2023-02-20 15:18:18 +01:00
Mårten Nordheim
22fc1d08bb Torrent example: delete unimplemented functions
That's not fit for an example...

Task-number: QTBUG-110622
Pick-to: 6.5
Change-Id: Ib196d61867f95f3ff2e45841509d49df9360ad25
Reviewed-by: Konrad Kujawa <konrad.kujawa@qt.io>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
2023-02-14 18:49:46 +01:00
Mårten Nordheim
3fc26dbb2c Torrent example: Convert some timeouts from int to chrono
Using seconds because then they all have the same type, even if
all-but-one could use minutes.
Delete one unused interval value.

Task-number: QTBUG-110622
Pick-to: 6.5
Change-Id: I66b456de8a4b867859e9e2b13ce72e8ec691c79a
Reviewed-by: Konrad Kujawa <konrad.kujawa@qt.io>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
2023-02-14 18:49:45 +01:00
Mårten Nordheim
69c31f6f68 Torrent example: Remove manual little-big endian conversion
... and use QtEndian instead.

The conversion would be done even on a big-endian system, so the
example would not work correctly on such machines.

Task-number: QTBUG-110622
Pick-to: 6.5
Change-Id: I6a660ff68fa5a8d9b4c1faf9e264d937c605c47e
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
2023-02-14 18:49:45 +01:00
Mårten Nordheim
2145341071 Delete googlesuggest
As a networking example it doesn't contribute much. But it has some
interesting uses of widget/events

Pick-to: 6.5
Change-Id: I194d32e6a304ae41819c20751e9f1ee1d9b5abdb
Reviewed-by: Konrad Kujawa <konrad.kujawa@qt.io>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2023-02-14 17:48:09 +01:00
Mårten Nordheim
7df8ef0a10 HTTP example: Reflow QMessageBox usage in if-statement
It gets hard to read like that.
And update mentions of 'SSL' to 'TLS' in the message while we're there.

Task-number: QTBUG-108874
Pick-to: 6.5
Change-Id: Ia7b27bfb3d99391b14ed396ca9a6400621022bf6
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2023-02-02 18:03:36 +00:00
Friedemann Kleint
93af309a70 Examples: Fix CMake Unity (Jumbo) builds
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>
2023-02-01 19:12:36 +01:00
Mårten Nordheim
39daa368d4 Torrent example: Use QByteArray toPercentEncoding
The hand-rolled loop produced incorrect output and was subsequently
rejected by trackers.

The torrent example doesn't support modern features though, so it's
still a bit hit-or-miss whether a torrent will work. E.g. downloading an
Arch iso does not work since it relies on DHT, PeX and HTTP seeds.

Fixes: QTBUG-109798
Task-number: QTBUG-110622
Pick-to: 6.5
Change-Id: Ica40fb9205f09d135407a160a28a45d06a418176
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2023-01-30 20:10:25 +01:00
Mårten Nordheim
6c90c04fb9 Torrent example: don't try to announce to an empty URL
Task-number: QTBUG-109798
Task-number: QTBUG-110622
Pick-to: 6.5
Change-Id: I3603232eb094387388da6421bf5525a3ba54fe03
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-01-30 20:10:25 +01:00
Mårten Nordheim
5006fddd33 HTTP Example: Add proxy handling
If a proxy is configured on the system then we will request credentials
if needed.

Task-number: QTBUG-108874
Fixes: QTBUG-106245
Pick-to: 6.5
Change-Id: Icbea491492cde4634421b1a1e722a3768d56dec8
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2023-01-24 20:11:53 +01:00
Mårten Nordheim
d18b5195c1 HTTP example: remove needlessly unset-ing window flag
In Qt 6 it is unset by default.

Task-number: QTBUG-108874
Pick-to: 6.5
Change-Id: I35af9d7c1517fd393710b7b1b978d3f39c61acf0
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2023-01-24 20:11:53 +01:00
Mårten Nordheim
c89c37b52f HTTP example: Fix missing translation and improve others
As a drive-by: print the path with native separators

Task-number: QTBUG-108874
Pick-to: 6.5
Change-Id: I73164acb159d1a45960e16d5f57996e8c27257f7
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
2023-01-24 20:11:53 +01:00
Mårten Nordheim
7c90881a8e HTTP example: rename to HTTP Client
It can do more than HTTP but let's keep the naming simple. Most people
likely aren't looking to do file: or data: or qrc: in this example.

Task-number: QTBUG-108874
Pick-to: 6.5
Change-Id: I8a822640f4a8015ebf6c56cb6a614d6426e8a912
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2023-01-24 20:11:53 +01:00
Mårten Nordheim
5bc644c951 Fortune* Example: Rename and add category/tags
Task-number: QTBUG-108875
Pick-to: 6.5
Change-Id: I8eeff88187be4f85514d9871eb5009c51ad6de64
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
2023-01-24 20:11:53 +01:00
Mårten Nordheim
2fe69dbeb8 Fortune* Example: remove needless unset-ing of window flag
It's unset by default in Qt6.

Task-number: QTBUG-108875
Pick-to: 6.5
Change-Id: I3f1c6e4e6de54e9ca0ed8892f9da1d346d16d4c7
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
2023-01-17 16:15:11 +01:00
Mårten Nordheim
71cd3bc074 Fortune* Example: Bump QDataStream format version
One of the examples were using a different version than the others.
Though QString's formatting probably didn't change since then so
it was no problem.

Anyway, pretend like we're releasing it now for the first time and
set 6.5 on all of them

Task-number: QTBUG-108875
Pick-to: 6.5
Change-Id: I28b496ab3d8ff54c503a032ba15882cdf3d5eccf
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
2023-01-17 16:15:11 +01:00
Mårten Nordheim
605eec7b55 Fortune* Example: convert simple for-loop to ranged-for
Ends up shortening the loop, making it easier to read at a glance.

Pick-to: 6.5
Task-number: QTBUG-108875
Change-Id: Ia12a994259b00e9b57f2de48124be9cb38553bf5
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
2023-01-17 16:15:11 +01:00
Mårten Nordheim
45717db7a5 Threaded Fortune Example: update example to use qintptr for descriptors
Pick-to: 6.5
Task-number: QTBUG-108875
Change-Id: Ie635a3d2c4c61a59547e8fed0ec84da8538968a3
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
2023-01-17 16:15:11 +01:00
Kai Köhne
25c67c608a Examples: Do not wrap custom types in Qt namespace
The Qt namespace should be used for types defined in the Qt library,
not for user types.

Pick-to: 6.5
Change-Id: I6df0ca054888f4a65b19a9cb44324321d1dcfad8
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
2023-01-02 23:16:30 +01:00
Samuel Gaist
e686a13b7b examples: port network examples to new connection style
Task-number: QTBUG-106893
Change-Id: Id0f558362108fedececb9eede36becc04ff4e307
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
2022-12-21 21:52:17 +01:00
Tor Arne Vestbø
465bde54a0 Remove showMaximized() workaround for Android in examples
Android implements QPlatformIntegration::ShowIsMaximized nowadays.

Change-Id: I451a9a8edc8ec407946d44f3e6921c78ac1d11aa
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-12-02 15:53:37 +01:00
Kai Köhne
a5de12f0d7 Examples: Use PRIVATE CMake linkage
We (almost) only build apps, for which PRIVATE linkage makes more sense.

Change-Id: I09a509c3fb33a00cdfdede687b3f95d638f42091
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
2022-11-30 14:48:50 +01:00
Andreas Eliasson
de7287be69 Doc: Fix typo and mismatch between code and description
Fixes: QTBUG-107675
Pick-to: 6.4 6.2
Change-Id: I38140617a2b0525db417137aa41a52a389b3bea3
Reviewed-by: Topi Reiniö <topi.reinio@qt.io>
2022-11-30 14:48:50 +01:00
Kai Köhne
f562711c64 Examples: Use qt_standard_project_setup()
Change-Id: I0ceab08108b7e58e4e2ed25db9e3c289f5c0ddac
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
2022-11-17 19:59:11 +01:00
Kai Köhne
bec264c15f Examples: Use Qt6:: to qualify Qt CMake packages
This is what we promote also in the documentation.

Change-Id: If91aebafe861b0c934acbb2c69afd182abc3345d
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
2022-11-17 19:59:11 +01:00