Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
|
\inmodule QtBluetooth More...
#include <qbluetoothlocaldevice.h>
Public Types | |
enum | Pairing { Unpaired , Paired , AuthorizedPaired } |
This enum describes the pairing state between the two Bluetooth devices. More... | |
enum | HostMode { HostPoweredOff , HostConnectable , HostDiscoverable , HostDiscoverableLimitedInquiry } |
This enum describes the most of the local Bluetooth device. More... | |
enum | Error { NoError , PairingError , MissingPermissionsError , UnknownError = 100 } |
This enum describes errors that maybe returned. More... | |
Signals | |
void | hostModeStateChanged (QBluetoothLocalDevice::HostMode state) |
The state of the host has transitioned to a different HostMode. | |
void | deviceConnected (const QBluetoothAddress &address) |
void | deviceDisconnected (const QBluetoothAddress &address) |
void | pairingFinished (const QBluetoothAddress &address, QBluetoothLocalDevice::Pairing pairing) |
Pairing or unpairing has completed with address. | |
void | errorOccurred (QBluetoothLocalDevice::Error error) |
Signal emitted if there's an exceptional error while pairing. | |
Signals inherited from QObject | |
void | destroyed (QObject *=nullptr) |
This signal is emitted immediately before the object obj is destroyed, after any instances of QPointer have been notified, and cannot be blocked. | |
void | objectNameChanged (const QString &objectName, QPrivateSignal) |
This signal is emitted after the object's name has been changed. | |
Public Member Functions | |
QBluetoothLocalDevice (QObject *parent=nullptr) | |
Constructs a QBluetoothLocalDevice with parent. | |
QBluetoothLocalDevice (const QBluetoothAddress &address, QObject *parent=nullptr) | |
Construct new QBluetoothLocalDevice for address. | |
virtual | ~QBluetoothLocalDevice () |
Destroys the QBluetoothLocalDevice. | |
bool | isValid () const |
void | requestPairing (const QBluetoothAddress &address, Pairing pairing) |
Set the pairing status with address. | |
Pairing | pairingStatus (const QBluetoothAddress &address) const |
Returns the current bluetooth pairing status of address, if it's unpaired, paired, or paired and authorized. | |
void | setHostMode (QBluetoothLocalDevice::HostMode mode) |
Sets the host mode of this local Bluetooth device to mode. | |
HostMode | hostMode () const |
Returns the current host mode of this local Bluetooth device. | |
QList< QBluetoothAddress > | connectedDevices () const |
void | powerOn () |
Powers on the device after returning it to the hostMode() state, if it was powered off. | |
QString | name () const |
Returns the name assgined by the user to this Bluetooth device. | |
QBluetoothAddress | address () const |
Returns the MAC address of this Bluetooth device. | |
Public Member Functions inherited from QObject | |
Q_INVOKABLE | QObject (QObject *parent=nullptr) |
Constructs an object with parent object parent. | |
virtual | ~QObject () |
Destroys the object, deleting all its child objects. | |
virtual bool | event (QEvent *event) |
This virtual function receives events to an object and should return true if the event e was recognized and processed. | |
virtual bool | eventFilter (QObject *watched, QEvent *event) |
Filters events if this object has been installed as an event filter for the watched object. | |
QString | objectName () const |
Q_WEAK_OVERLOAD void | setObjectName (const QString &name) |
Sets the object's name to name. | |
void | setObjectName (QAnyStringView name) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
QBindable< QString > | bindableObjectName () |
bool | isWidgetType () const |
Returns true if the object is a widget; otherwise returns false . | |
bool | isWindowType () const |
Returns true if the object is a window; otherwise returns false . | |
bool | isQuickItemType () const |
Returns true if the object is a QQuickItem; otherwise returns false . | |
bool | signalsBlocked () const noexcept |
Returns true if signals are blocked; otherwise returns false . | |
bool | blockSignals (bool b) noexcept |
If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). | |
QThread * | thread () const |
Returns the thread in which the object lives. | |
bool | moveToThread (QThread *thread QT6_DECL_NEW_OVERLOAD_TAIL) |
Changes the thread affinity for this object and its children and returns true on success. | |
int | startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer) |
This is an overloaded function that will start a timer of type timerType and a timeout of interval milliseconds. | |
int | startTimer (std::chrono::nanoseconds time, Qt::TimerType timerType=Qt::CoarseTimer) |
void | killTimer (int id) |
Kills the timer with timer identifier, id. | |
void | killTimer (Qt::TimerId id) |
template<typename T > | |
T | findChild (QAnyStringView aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
Returns the child of this object that can be cast into type T and that is called name, or \nullptr if there is no such object. | |
template<typename T > | |
QList< T > | findChildren (QAnyStringView aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. | |
template<typename T > | |
T | findChild (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
template<typename T > | |
QList< T > | findChildren (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
const QObjectList & | children () const |
Returns a list of child objects. | |
void | setParent (QObject *parent) |
Makes the object a child of parent. | |
void | installEventFilter (QObject *filterObj) |
Installs an event filter filterObj on this object. | |
void | removeEventFilter (QObject *obj) |
Removes an event filter object obj from this object. | |
QMetaObject::Connection | connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const |
bool | disconnect (const char *signal=nullptr, const QObject *receiver=nullptr, const char *member=nullptr) const |
bool | disconnect (const QObject *receiver, const char *member=nullptr) const |
void | dumpObjectTree () const |
Dumps a tree of children to the debug output. | |
void | dumpObjectInfo () const |
Dumps information about signal connections, etc. | |
bool | setProperty (const char *name, const QVariant &value) |
Sets the value of the object's name property to value. | |
bool | setProperty (const char *name, QVariant &&value) |
QVariant | property (const char *name) const |
Returns the value of the object's name property. | |
QList< QByteArray > | dynamicPropertyNames () const |
QBindingStorage * | bindingStorage () |
const QBindingStorage * | bindingStorage () const |
QObject * | parent () const |
Returns a pointer to the parent object. | |
bool | inherits (const char *classname) const |
Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false . | |
Static Public Member Functions | |
static QList< QBluetoothHostInfo > | allDevices () |
Returns a list of all available local Bluetooth devices. | |
Static Public Member Functions inherited from QObject | |
static QMetaObject::Connection | connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection) |
\threadsafe | |
static QMetaObject::Connection | connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection) |
template<typename Func1 , typename Func2 > | |
static QMetaObject::Connection | connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::ContextTypeForFunctor< Func2 >::ContextType *context, Func2 &&slot, Qt::ConnectionType type=Qt::AutoConnection) |
template<typename Func1 , typename Func2 > | |
static QMetaObject::Connection | connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 &&slot) |
static bool | disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member) |
\threadsafe | |
static bool | disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member) |
static bool | disconnect (const QMetaObject::Connection &) |
Disconnect a connection. | |
template<typename Func1 , typename Func2 > | |
static bool | disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiver, Func2 slot) |
template<typename Func1 > | |
static bool | disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *receiver, void **zero) |
Additional Inherited Members | |
Public Slots inherited from QObject | |
void | deleteLater () |
\threadsafe | |
Protected Member Functions inherited from QObject | |
QObject * | sender () const |
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns \nullptr. | |
int | senderSignalIndex () const |
int | receivers (const char *signal) const |
Returns the number of receivers connected to the signal. | |
bool | isSignalConnected (const QMetaMethod &signal) const |
virtual void | timerEvent (QTimerEvent *event) |
This event handler can be reimplemented in a subclass to receive timer events for the object. | |
virtual void | childEvent (QChildEvent *event) |
This event handler can be reimplemented in a subclass to receive child events. | |
virtual void | customEvent (QEvent *event) |
This event handler can be reimplemented in a subclass to receive custom events. | |
virtual void | connectNotify (const QMetaMethod &signal) |
virtual void | disconnectNotify (const QMetaMethod &signal) |
QObject (QObjectPrivate &dd, QObject *parent=nullptr) | |
Protected Attributes inherited from QObject | |
QScopedPointer< QObjectData > | d_ptr |
Properties inherited from QObject | |
QString | objectName |
the name of this object | |
Related Symbols inherited from QObject | |
template< class T > T | qobject_cast (const QObject *object) |
Returns the given object cast to type T if the object is of type T (or of a subclass); otherwise returns \nullptr. | |
template< typename T > T | qFindChildqFindChildren (const QObject *obj, const QString &name)() |
template< typename T > QList< T > | qFindChildrenqFindChildren (const QObject *obj, const QString &name)() |
QObjectList | |
\macro Q_CLASSINFO(Name, Value) | |
\inmodule QtBluetooth
The QBluetoothLocalDevice class enables access to the local Bluetooth device.
QBluetoothLocalDevice provides functions for getting and setting the state of local Bluetooth devices.
On iOS, this class cannot be used because the platform does not expose any data or API which may provide information on the local Bluetooth device.
Definition at line 19 of file qbluetoothlocaldevice.h.
This enum describes errors that maybe returned.
\value NoError No known error \value PairingError Error in pairing \value [since 6.4] MissingPermissionsError The operating system requests permissions which were not granted by the user. \value UnknownError Unknown error
Enumerator | |
---|---|
NoError | |
PairingError | |
MissingPermissionsError | |
UnknownError |
Definition at line 39 of file qbluetoothlocaldevice.h.
This enum describes the most of the local Bluetooth device.
\value HostPoweredOff Power off the device \value HostConnectable Remote Bluetooth devices can connect to the local Bluetooth device if they have previously been paired with it or otherwise know its address. This powers up the device if it was powered off. \value HostDiscoverable Remote Bluetooth devices can discover the presence of the local Bluetooth device. The device will also be connectable, and powered on. On Android, this mode can only be active for a maximum of 5 minutes. \value HostDiscoverableLimitedInquiry Remote Bluetooth devices can discover the presence of the local Bluetooth device when performing a limited inquiry. This should be used for locating services that are only made discoverable for a limited period of time. This can speed up discovery between gaming devices, as service discovery can be skipped on devices not in LimitedInquiry mode. In this mode, the device will be connectable and powered on, if required. This mode is is not supported on Android.
Enumerator | |
---|---|
HostPoweredOff | |
HostConnectable | |
HostDiscoverable | |
HostDiscoverableLimitedInquiry |
Definition at line 31 of file qbluetoothlocaldevice.h.
This enum describes the pairing state between the two Bluetooth devices.
\value Unpaired The Bluetooth devices are not paired. \value Paired The Bluetooth devices are paired. The system will prompt the user for authorization when the remote device initiates a connection to the local device. \value AuthorizedPaired The Bluetooth devices are paired. The system will not prompt the user for authorization when the remote device initiates a connection to the local device.
Enumerator | |
---|---|
Unpaired | |
Paired | |
AuthorizedPaired |
Definition at line 24 of file qbluetoothlocaldevice.h.
Constructs a QBluetoothLocalDevice with parent.
android-permissions-valid
Definition at line 146 of file qbluetoothlocaldevice_android.cpp.
|
explicit |
Construct new QBluetoothLocalDevice for address.
If address is default constructed the resulting local device selects the local default device.
android-permissions-valid
Definition at line 152 of file qbluetoothlocaldevice_android.cpp.
|
virtual |
Destroys the QBluetoothLocalDevice.
Definition at line 112 of file qbluetoothlocaldevice.cpp.
QBluetoothAddress QBluetoothLocalDevice::address | ( | ) | const |
Returns the MAC address of this Bluetooth device.
{02
:00:00:00:00:00} as local address starting with Android 6.0. The programmatic access to the device's local MAC address was removed. Definition at line 166 of file qbluetoothlocaldevice_android.cpp.
|
static |
Returns a list of all available local Bluetooth devices.
On \macos, there is only the "default" local device.
Definition at line 287 of file qbluetoothlocaldevice_android.cpp.
QList< QBluetoothAddress > QBluetoothLocalDevice::connectedDevices | ( | ) | const |
Returns the list of connected devices. This list is different from the list of currently paired devices.
On Android and \macos, it is not possible to retrieve a list of connected devices. It is only possible to listen to (dis)connect changes. For convenience, this class monitors all connect and disconnect events since its instanciation and returns the current list when calling this function. Therefore it is possible that this function returns an empty list shortly after creating an instance.
Definition at line 378 of file qbluetoothlocaldevice_android.cpp.
|
signal |
This signal is emitted when the local device establishes a connection to a remote device with address.
|
signal |
This signal is emitted when the local device disconnects from a remote Bluetooth device with address.
|
signal |
Signal emitted if there's an exceptional error while pairing.
QBluetoothLocalDevice::HostMode QBluetoothLocalDevice::hostMode | ( | ) | const |
Returns the current host mode of this local Bluetooth device.
On \macos, it is either HostPoweredOff or HostConnectable.
Definition at line 267 of file qbluetoothlocaldevice_android.cpp.
|
signal |
The state of the host has transitioned to a different HostMode.
bool QBluetoothLocalDevice::isValid | ( | ) | const |
Returns \c true if the QBluetoothLocalDevice represents an available local Bluetooth device; otherwise return false. If the local Bluetooth adapter represented by an instance of this class is removed from the system (e.g. removal of the underlying Bluetooth dongle) then this instance will become invalid. An already invalid QBluetoothLocalDevice instance remains invalid even if the same Bluetooth adapter is returned to the system.
! [android-permissions-valid]
\sa allDevices()
Definition at line 136 of file qbluetoothlocaldevice.cpp.
QString QBluetoothLocalDevice::name | ( | ) | const |
Returns the name assgined by the user to this Bluetooth device.
Definition at line 158 of file qbluetoothlocaldevice_android.cpp.
Referenced by testing.tools.encode_pdf_filter._PdfStream::RegisterByName().
|
signal |
Pairing or unpairing has completed with address.
Current pairing status is in pairing. If the pairing request was not successful, this signal will not be emitted. The errorOccurred() signal is emitted if the pairing request failed. The signal is only ever emitted for pairing requests which have previously requested by calling \l requestPairing() of the current object instance.
QBluetoothLocalDevice::Pairing QBluetoothLocalDevice::pairingStatus | ( | const QBluetoothAddress & | address | ) | const |
Returns the current bluetooth pairing status of address, if it's unpaired, paired, or paired and authorized.
Definition at line 353 of file qbluetoothlocaldevice_android.cpp.
void QBluetoothLocalDevice::powerOn | ( | ) |
Powers on the device after returning it to the hostMode() state, if it was powered off.
Definition at line 176 of file qbluetoothlocaldevice_android.cpp.
void QBluetoothLocalDevice::requestPairing | ( | const QBluetoothAddress & | address, |
Pairing | pairing ) |
Set the pairing status with address.
The results are returned by the signal, pairingFinished().
On Android and \macos, AuthorizedPaired is not possible and will have the same behavior as Paired. On Windows the exact pairing mode decision is up to the operating system.
On \macos, it is not possible to unpair a device. If Unpaired is requested, \l pairingFinished() is immediately emitted although the device remains paired. It is possible to request the pairing for a previously unpaired device. In addition \l AuthorizedPaired has the same behavior as \l Paired.
Caution: creating a pairing may take minutes, and may require the user to acknowledge.
Definition at line 308 of file qbluetoothlocaldevice_android.cpp.
void QBluetoothLocalDevice::setHostMode | ( | QBluetoothLocalDevice::HostMode | mode | ) |
Sets the host mode of this local Bluetooth device to mode.
Some transitions such as turning the device on or off may take some time. Therefore subsequent calls should only be made once the \l hostModeStateChanged() signal has concluded the previous request. If this is ignored the result of such a series of calls is not well defined.
Definition at line 197 of file qbluetoothlocaldevice_android.cpp.