Commit Graph

237 Commits

Author SHA1 Message Date
Marc Mutz 4d975c3ffc Port simple cases of count() to size()
The count() methods on QByteArray and QString are deprecated. The ones
on other Qt containers will likely follow soon, so port them all to
size().

The changes which also require int -> qsizetype will come in a
follow-up patch.

Pick-to: 6.3
Change-Id: I23e364019b9cfc457d93f4a3bb4660fe8d790da8
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Juha Vuolle <juha.vuolle@insta.fi>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2022-04-11 15:21:46 +02:00
Juha Vuolle d4b1a61229 Add bluetooth example app Qt::Gui linkage on iOS
Fixes: QTBUG-101720
Pick-to: 6.3
Change-Id: I5d6e1e51ef73521390a3903b8ff1f225ea5dfa83
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2022-03-18 07:09:15 +02:00
Kai Köhne 9957794353 Improve examples CMakeLists.txt
- Remove automatic use of CMAKE_AUTORCC
- Only opt into CMAKE_AUTOUIC if .ui files are involved
- Remove explicit setting of CMAKE_INCLUDE_CURRENT_DIR
- Combine multiple find_package(Qt6 ... calls)
 - use REQUIRED COMPONENTS
 - sort components alphabetically
- Fix wrong indentations
- Use (only) one empty line after multi-line commands

Pick-to: 6.3
Change-Id: If1935beb09edd873c45842ae06d0f41267a9b36a
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
2022-02-21 10:25:16 +01:00
Juha Vuolle 788c4980e6 Avoid multiple client sockets in pingpong bluetooth example
This commit guards against creating multiple client sockets if multiple
services are found. In addition the service scanning is stopped when
a service has been found and we start connecting a bluetooth socket.

Fixes: QTBUG-100289
Pick-to: 5.15 6.2 6.3
Change-Id: Iac2e7eaca17a186ac2d2f62e338be16911f08032
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
2022-02-12 17:17:03 +02:00
Oliver Wolff 215b7bea76 btscanner example: Add option to stop a running scan
Change-Id: Id82f6c903938e289559a79b4a2383ad20944c61a
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2022-01-26 13:07:46 +01:00
Ivan Solovev 4d2df2461f PingPong example: let the parent QObject do the cleanup
The m_timer and m_serverInfo instances are created using 'this' as a
parent, so we do not need to explicitly delete them in the destructor,
but let the parent object deal with them.
This also prevents a crash at application close.

Pick-to: 6.3 6.2 5.15
Change-Id: If91f01e1ab6dc8e839a06773464eeb9858d2fd36
Reviewed-by: Juha Vuolle <juha.vuolle@insta.fi>
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2022-01-21 15:50:36 +01:00
Juha Vuolle debf0fd212 Store the serviceinfo in pingpong example
The service info returned by the QBluetoothServer::listen() overload
that returns it needs to be stored or otherwise it will be destroyed.

The consequence was that the SDP "advertisement" didn't properly
include the added pingpong service record on Windows.

Task-number: QTBUG-100042
Pick-to: 6.2 6.3 5.15
Change-Id: I79cbd0f574e35bbc1c9c3123ce8382f3aad296d4
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2022-01-21 15:07:46 +02:00
Alexandru Croitor 0d9dc44fef Switch examples to build as isolated sub-builds
Pick-to: 6.2 6.3
Task-number: QTBUG-90820
Change-Id: Ife7b112e7a800460740f21a69d2ac85133bf0827
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
2021-12-15 12:54:41 +01:00
Ivan Solovev adcfc156f4 BtChat: fix crash when no adapter is found
The example was assuming that QBluetoothLocalDevice::allDevices() always
returns a non-empty list.
This is not true for the cases when desktop has no bluetooth adapters,
as well as for WinRT implementation (it always returns empty list for now).

This patch fixes the crash and provides some information messages to the
console. Note that WinRT implementation has an extended warning, because
it returns an empty list even if the adapter actually exists.

Fixes: QTBUG-98323
Pick-to: 6.2
Change-Id: Iaa81465cf6be2febf20526c11909667fd60728b3
Reviewed-by: Juha Vuolle <juha.vuolle@insta.fi>
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2021-11-16 09:58:31 +01:00
Juha Vuolle 70d590a81c macOS specific Info.plist file for Bluetooth Examples
The default generated Info.plist is not enough as the Bluetooth examples
require NSBluetoothAlwaysUsageDescription key to work. Without this
patch on macOS 12 there are two possible outcomes:
1) If the example is built with qmake, the application will crash
   and the crash report will indicate that the key is missing
2) If the example is built with CMake, the application will not start
   as it tries to use iOS specific .plist file

The patch uses absolute paths in the example CMakeLists.txt files
to work around a Ninja bug:
https://gitlab.kitware.com/cmake/cmake/-/issues/20181
Using relative paths resulted in "multiple rules generate" errors
if the QtConnectivity module is built with examples.

Note that the plist files are only effective if the application is
started as an app bundle, ie. not if launching the contained binary
directly.

Pick-to: 6.2
Task-number: QTBUG-98090
Change-Id: Iedb7eabbb8fde6ad1ba14ada1a7ee87ec1d708ba
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2021-11-11 08:19:15 +02:00
Juha Vuolle f1977883ad Fix 'width' of 'null' QML warnings in lowenergyscanner example
As per Qt documentation in
https://doc.qt.io/qt-5/qml-qtquick-listview.html#example-usage
the parent of a delegate can change and be 'null' at times.
This commit refers explicitly to the containing view instead.

Change-Id: I9c9a8c907daba2b6de52a246ae71cfde0c27e55b
Fixes: QTBUG-97691
Pick-to: 6.2
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Andreas Buhr <andreas.buhr@qt.io>
2021-10-25 09:50:31 +03:00
Friedemann Kleint cd540c71ba Polish the btscanner example
- Use Qt 5 connection syntax
- Use a QDialogButtonBox instead of a single button in the service dialog
- Forward-declare the UI classes
- Streamline code

Pick-to: 6.2
Change-Id: I30db78043a8e3a62ea10223252a59b8415296e55
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2021-10-19 14:39:07 +02:00
Juha Vuolle ab63bfa4ef Remove float => double truncation compilation warning on MSVC
Explicitly declare numbers stored to floats as floats

Pick-to: 6.2
Change-Id: Id1e9d5a5e393dbad0c0fec7aac3083d6e62403cc
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2021-09-17 08:19:52 +03:00
Timur Pocheptsov d4546e76a5 Bluetooth (examples): update CMakeLists.txt to include Info.plist
Pick-to: 6.2
Change-Id: I87097dc605ff34db1f8d7fb92d055402693906e1
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2021-09-10 19:05:36 +02:00
Juha Vuolle 956e7bbe21 Remove error messages on lowenergyscanner example app exit
The QML View was created on heap and outlived the 'device'
context property on stack. This resulted in distracting
'null' property access errors on exit.

In addition remove unnecessary QML import versioning.

Pick-to: 6.2
Change-Id: I5cb7d219582ef8e9a72a3f7e514e78fb16a54e2f
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Andreas Buhr <andreas.buhr@qt.io>
2021-09-09 16:54:13 +03:00
Timur Pocheptsov e01660fbe5 QtBluetooth (examples): add Info.plist for iOS
btscanner example can be built and deployed on iOS, but then it requires
special entries in its Info.plist, explaining the usage of BT adapter.

Pick-to: 6.2 5.15
Change-Id: I86edfe84a19f4da8173bb5374fb10e55811a4b20
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2021-09-09 10:21:40 +02:00
Timur Pocheptsov 42e1fdacd5 CoreBluetooth: provide a description (in Info.plist) of BT usage
Our lowenergyscanner example can be built and deployed on iOS device.
As such, it has to provide an explanation, why it needs an access to
BT adapter, otherwise, it would crash with the most recent versions
of iOS.

Pick-to: 6.2 5.15
Change-Id: Iebcdf8af931002532aada0c452263effd342300e
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2021-09-09 10:21:36 +02:00
Timur Pocheptsov 0e836b5a8b Heart-rate example: add a proper Info.plist
Apple (iOS) requires a "proper" Info.plist entries, explaining _why_
we want to use Bluetooth on this particular device. So, let's add it.
Both the server and game apps need it.

Fixes: QTBUG-93991
Pick-to: 5.15 6.2
Change-Id: I09133c6714f30bc402049cd40969a9b9644a0b4f
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2021-09-07 16:11:45 +02:00
Joerg Bornemann dd9e9b5722 Raise cmake_minimum_required to VERSION 3.16 in examples
Pick-to: 6.2
Task-number: QTBUG-95636
Change-Id: I2ae5ba6164cb5ed450c8924d484d30167461c10d
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2021-08-17 13:47:58 +02:00
Andreas Buhr a19905f937 Fix wrong image in QML pingpong example documentation
Because of a name clash, a wrong image was shown in the
documentation of the QML pingpong example. This patch changes the
filename to prevent the name clash.

Fixes: QTBUG-94192
Change-Id: I4e27b4b9a05efe9c1766a256305ead16a09fa9c7
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
2021-06-24 09:22:37 +02:00
Andreas Buhr 0f860d2d98 Increase timeout of lowenergyscanner
The low timeout of five seconds leads to lots of frustration.
This patch extends to 25 seconds, which is most of the time
long enough.

Pick-to: 6.2
Change-Id: I2157ac0e794011a65e306dd7451e35e1bc0e7c8d
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2021-06-14 17:16:23 +02:00
Ville Voutilainen 7d2c6ae66f Remove AndroidExtras dependencies and port to new Qt 6 Android APIs
Task-number: QTBUG-93811
Change-Id: Ia3eb9ad90f27614db5997e1f41f13e050f5f4ab7
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Rami Potinkara <rami.potinkara@qt.io>
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
Reviewed-by: Andreas Buhr <andreas.buhr@qt.io>
2021-06-04 15:08:23 +03:00
Andreas Buhr bff824d67b Make QLECharacteristic::handle() and QLEDescriptor::handle() private
Task-number: QTBUG-62877
Task-number: QTBUG-94138
Change-Id: Id8c98e267c9b16f77a63f63f41638efbe627acaa
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2021-06-03 11:47:38 +02:00
Alex Blasche c1237aab79 Fix binary name clash with qtscxml example
See qtscxml/examples/statemachine/statemachine/pingpong for reference

Fixes: QTBUG-92985
Change-Id: I00c2cb39d0f72be0790e55ce31419c5883b34e32
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2021-04-26 14:23:55 +02:00
Andreas Buhr 62cc018b3c Change QLowEnergyService::ServiceState enum to reflect future changes
In the future, discoverDetails() should become optional.
The state of a QLowEnergyService after its creation should have
a name which does not imply it is not functional yet. This patch
changes the name of the initial state from "DiscoveryRequired"
to the neutral "RemoteService".

Task-number: QTBUG-75340
Change-Id: Ib407e60f5fc7264a04a124561dacbcebb01bf252
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2021-04-08 16:57:19 +02:00
Andreas Buhr 75c3a3ee9f rename error signals to errorOccurred
Currently, there is a name clash between the error getter and
the error signal. This leads to extensive use of qOverload or
similar. This patch renames all error signals to errorOccurred
to resolve this.

Task-number: QTBUG-62877
Change-Id: I615e2405f855433b6e142d820072c4d3f35ae28f
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2021-03-22 13:51:28 +01:00
Andreas Buhr e009d67f4b Decouple QBluetoothSocket and QAbstractSocket, introduce scoped enums
QBluetoothSocket enum values were tied to QAbstractSocket enum values.
But there is no dependency, the coupling is not required. This patch
removes the coupling and changes to scoped enums for improved type
safety.

Task-number: QTBUG-62877
Change-Id: I206b1d438d74b976d3e0d32da5713d22b597dd90
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2021-03-12 09:05:35 +01:00
Andreas Buhr 74abfd114f Update screenshots in QtBluetooth Example documentation
Change-Id: Ie0f602e875604f592bc689f6f3ecc00133e9960f
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2021-03-11 15:39:47 +01:00
Andreas Buhr 66bb9839db Use scoped enum for constants in QBluetoothUuid
QBluetoothUuid contains enums for ProtocolUuid, ServiceClassUuid,
CharacteristicType and DescriptorType. So far, they all
put their constants directly into the QBluetoothUuid
namespace, making it easy to mix them up. This patch changes
those to scoped enums. That way, each enum has its items in
its own namespace.

Change-Id: I86ea08ff31009dc8073d84cfe678e27920d693f7
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2021-03-11 13:01:51 +01:00
Andreas Buhr 61e2bab1d0 Pingpong example: update documentation
This patch updates the documentation of the pingpong example
to the changes made.

Change-Id: I4ebe3848b71a8edb61fd359a8d8d2af9c05494c8
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2021-03-11 09:14:21 +01:00
Andreas Buhr d2e9a5113e Pingpong example: Add convex paddles and speedup
Game logic of the pingpong example was a bit boring, because the
angle of the ball never changed. This patch adds convex paddles.
The surface of the paddle is simulated to be a quarter of a circle.
Also, in each reflection, the speed of the ball increases.

Change-Id: I208e7322f2b4b849118d98959a6076458d20f409
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2021-03-05 15:21:25 +01:00
Andreas Buhr 4b9c6e6934 Pingpong example: Restart game at end
To play again, it was necessary to restart the whole executable.
This patch restarts the game at the end so that players can keep
playing.

Change-Id: I593a57862d449631d8f93b7d8e3cb56314f4fedd
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2021-03-05 15:21:21 +01:00
Andreas Buhr adbeef4d07 Pingpong example: Gamelogic works on unit square
The two parties playing pingpong agreed on a screen size in the past.
This patch changes the logic to work on the unit square (0,1)x(0,1).
Visualization scales this up to window size. This patch also
simplifies the position update loop

Change-Id: Ie89b1eaa5fc14daf6b56cd42458a16ae0a923568
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2021-03-05 15:21:16 +01:00
Andreas Buhr dd6c822763 Pingpong example: User 600x600 window by default, fullscreen on mobile
With this patch, the pingpong example no longer forces the
use of a 600x300 window on mobile devices, which led to a suboptimal
user experience.

Change-Id: I2365542bc8d5f99d015499f9b7e8c14ec5a93237
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2021-03-03 11:15:42 +01:00
Andreas Buhr 2988f97b5c Pingpong example: enlarge MouseArea for paddles
On some devices, it was hard to grab the paddles. This patch
enlarges the mousearea to easier grab the paddles.

Change-Id: I10d15b7605521d6a8d7775e5b6b96bce61e44de4
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2021-03-03 11:15:38 +01:00
Andreas Buhr 3f97ef4a14 Pingpong example: use square area for playing
This patch adds an extra rectangle to keep the playing area square.

Change-Id: I79a80c511eab8f0af44a98e5ff2ee74a88781fad
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2021-03-03 11:15:33 +01:00
Andreas Buhr 8bf9de22e1 Pingpong example: nicer ball visualization
Increase the ball by a factor of 2. Also remove NumberAnimation
which was not working anyway. Correct radius.

Change-Id: I4f0e5d50a7eb192a0743533f35e77809be77186a
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2021-03-03 11:15:18 +01:00
Andreas Buhr fe8ee78403 Pingpong example: move properties and event handlers
Reorganize code to have graphical elements and event handlers
separated

Change-Id: I64480649e7bf077b0e63193250a4cb0fe6be699d
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2021-03-03 11:15:10 +01:00
Andreas Buhr d031ee460d Pingpong example: make paddle shape independent of scale
This patch changes the paddle radius to be half of its width.
This way, the shape is independent of the size  of the window.

Change-Id: I1a959293e7cab0fdf320e879f828592b2b3b5f1a
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2021-03-03 11:14:59 +01:00
Andreas Buhr 148d987567 Remove QML API from QtBluetooth
This patch removes the BluetoothDiscoveryModel,
QDeclarativeBluetoothService, and QDeclarativeBluetoothSocket.
It also removes the "scanner" example and the "chat" example,
both using BluetoothDiscoveryModel.

Fixes: QTBUG-75354
Task-number: QTBUG-62877
Change-Id: Id9f6a75330e81c97ae9cd3fcaec793d0224ce72b
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2021-03-01 12:04:57 +01:00
Alex Blasche fbc88b414c Fix clazy warning
Missing reference in range-for with non trivial type (QBluetoothDeviceInfo)

Change-Id: I6f2e3092054376fdc52acdbeba149fe1a02b88fe
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Reviewed-by: Andreas Buhr <andreas.buhr@qt.io>
2021-02-26 17:00:35 +01:00
Andreas Buhr 6e7911f949 Remove QBluetoothTransferManager and friends
This patch removes QBluetoothTransferManager,
QBluetoothTransferReply and QBluetoothTransferRequest.
Furthermore, the examples "btfiletransfer" and "picturetransfer"
are removed.

Fixes: QTBUG-75353
Task-number: QTBUG-62877
Change-Id: Ife192d80196249185df877fb6a4cae317d7e44ad
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2021-02-26 11:49:59 +01:00
Andreas Buhr 152de81bba Correct documentation of heartrate-game example
Documentation of the heartrate-game example stated that a demo
mode is used if no devices are available, which is untrue.
This patch corrects the documentation to state that a demo mode
can be activated with a compile-time switch, which is true.

Change-Id: Ia7b7e9f524f8bd3f9c341c74b73e119faf6ebdaa
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2021-02-25 17:12:48 +01:00
Andreas Buhr 5fafa83909 Unify logging preparation across bluetooth examples
This patch streamlines all bluetooth examples to have
logging prepared, but not activated, in main().

Change-Id: Idbc81e2937c56acdc17c8fb81de2b8afe384608d
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2021-02-25 17:12:46 +01:00
Andreas Buhr ef8e9ce1e7 Bring btchat example documentation in line with implementation
Btchat example documentation mentioned a QRfcommServer where
a QBluetoothServer is created. This patch updates the documentation.

Change-Id: I1278a4c576aea8d5745dbb8405b1401a27d02146
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2021-02-24 10:30:47 +01:00
Andreas Buhr 13e48b009e Fix Android build of heartrate-server
The heartrate-server example links Qt::Gui on Android. But
Qt::Gui was not found using find_package. This patch adds
the missing find_package() call

Change-Id: I54e98f4959964c8730cdddda6ef8a6d4501ec866
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2021-02-23 16:50:57 +01:00
Andreas Buhr 160e28b303 Fix deprecation warnings in lowenergyscanner example
This patch fixes several warnings like
assets/Services.qml:81:5: QML Connections: Implicitly defined onFoo
properties in Connections are deprecated. Use this syntax instead:
function onFoo(<arguments>) { ... }

Change-Id: Ic4af8f2fc76e437f7b4113e691f2b2461b273bbb
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2021-02-23 16:50:21 +01:00
Andreas Buhr 23cd59e767 Fix warning about deprecated parameter injection
This patch fixes the warning
Injection of parameters into signal handlers is deprecated. Use
JavaScript functions with formal parameters instead.

Change-Id: Ibc8a0c3e1d8938a2da616303427df8f78dfa9aa2
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2021-02-22 18:00:13 +01:00
Andreas Buhr a859cad4a3 Fix error in qml_scanner visualization
This patch fixes the error
qrc:/scanner.qml:122: TypeError: Cannot read property 'width' of null

Change-Id: I4d12403e790d2e5203bdbab0d31acef3016f2399
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2021-02-22 18:00:11 +01:00
Andreas Buhr df07116930 Fix error in heartrate-game example
This patch fixes the error
qml/Connect.qml:103: TypeError: Cannot read property 'width' of null

Change-Id: I6592d603eee21684460d133df5f37fbcc9bc4fc8
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2021-02-22 17:59:54 +01:00