Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
QNearFieldTarget Class Reference

The QNearFieldTarget class provides an interface for communicating with a target device. More...

#include <qnearfieldtarget.h>

+ Inheritance diagram for QNearFieldTarget:
+ Collaboration diagram for QNearFieldTarget:

Classes

class  RequestId
 \inmodule QtNfc \inheaderfile QNearFieldTarget More...
 
class  RequestIdPrivate
 

Public Types

enum  Type {
  ProprietaryTag , NfcTagType1 , NfcTagType2 , NfcTagType3 ,
  NfcTagType4 , NfcTagType4A , NfcTagType4B , MifareTag
}
 This enum describes the type of tag the target is detected as. More...
 
enum  AccessMethod { UnknownAccess = 0x00 , NdefAccess = 0x01 , TagTypeSpecificAccess = 0x02 , AnyAccess = 0xff }
 This enum describes the access methods a near field target supports. More...
 
enum  Error {
  NoError , UnknownError , UnsupportedError , TargetOutOfRangeError ,
  NoResponseError , ChecksumMismatchError , InvalidParametersError , ConnectionError ,
  NdefReadError , NdefWriteError , CommandError , TimeoutError ,
  UnsupportedTargetError
}
 This enum describes the error codes that a near field target reports. More...
 

Signals

void disconnected ()
 This signal is emitted when the near field target moves out of proximity.
 
void ndefMessageRead (const QNdefMessage &message)
 This signal is emitted when a complete NDEF message has been read from the target.
 
void requestCompleted (const QNearFieldTarget::RequestId &id)
 This signal is emitted when a request id completes.
 
void error (QNearFieldTarget::Error error, const QNearFieldTarget::RequestId &id)
 This signal is emitted when an error occurs while processing request id.
 
- 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

 QNearFieldTarget (QObject *parent=nullptr)
 Constructs a new near field target with parent.
 
 ~QNearFieldTarget ()
 Destroys the near field target.
 
QByteArray uid () const
 Returns the UID of the near field target.
 
Type type () const
 Returns the type of tag type of this near field target.
 
AccessMethods accessMethods () const
 Returns the access methods supported by this near field target.
 
bool disconnect ()
 
bool hasNdefMessage ()
 Returns true if at least one NDEF message is stored on the near field target; otherwise returns false.
 
RequestId readNdefMessages ()
 Starts reading NDEF messages stored on the near field target.
 
RequestId writeNdefMessages (const QList< QNdefMessage > &messages)
 Writes the NDEF messages in messages to the target.
 
int maxCommandLength () const
 
RequestId sendCommand (const QByteArray &command)
 Sends command to the near field target.
 
bool waitForRequestCompleted (const RequestId &id, int msecs=5000)
 Waits up to msecs milliseconds for the request id to complete.
 
QVariant requestResponse (const RequestId &id) const
 Returns the decoded response for request id.
 
- 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< QStringbindableObjectName ()
 
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).
 
QThreadthread () 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 >
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 >
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 QObjectListchildren () 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< QByteArraydynamicPropertyNames () const
 
QBindingStoragebindingStorage ()
 
const QBindingStoragebindingStorage () const
 
QObjectparent () 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.
 

Protected Member Functions

 QNearFieldTarget (QNearFieldTargetPrivate *backend, QObject *parent=nullptr)
 
- Protected Member Functions inherited from QObject
QObjectsender () 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)
 

Friends

class QNearFieldManagerPrivateImpl
 

Additional Inherited Members

- Public Slots inherited from QObject
void deleteLater ()
 \threadsafe
 
- 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)
 
- Protected Attributes inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Properties inherited from QObject
QString objectName
 the name of this object
 

Detailed Description

The QNearFieldTarget class provides an interface for communicating with a target device.

\inmodule QtNfc

Since
5.2

QNearFieldTarget provides a generic interface for communicating with an NFC target device. Both NFC Forum devices and NFC Forum Tag targets are supported by this class. All target specific classes subclass this class.

The type() function can be used to get the type of the target device. The uid() function returns the unique identifier of the target. The AccessMethods flags returns from the accessMethods() function can be tested to determine which access methods are supported by the target.

If the target supports NdefAccess, hasNdefMessage() can be called to test if the target has a stored NDEF message, readNdefMessages() and writeNdefMessages() functions can be used to get and set the NDEF message.

If the target supports TagTypeSpecificAccess, sendCommand() can be used to send a single proprietary command to the target and retrieve the response.

Definition at line 21 of file qnearfieldtarget.h.

Member Enumeration Documentation

◆ AccessMethod

This enum describes the access methods a near field target supports.

\value UnknownAccess The target supports an unknown access type. \value NdefAccess The target supports reading and writing NDEF messages using readNdefMessages() and writeNdefMessages(). \value TagTypeSpecificAccess The target supports sending tag type specific commands using sendCommand(). \value AnyAccess The target supports any of the known access types.

Enumerator
UnknownAccess 
NdefAccess 
TagTypeSpecificAccess 
AnyAccess 

Definition at line 41 of file qnearfieldtarget.h.

◆ Error

This enum describes the error codes that a near field target reports.

\value NoError No error has occurred. \value UnknownError An unidentified error occurred. \value UnsupportedError The requested operation is unsupported by this near field target. \value TargetOutOfRangeError The target is no longer within range. \value NoResponseError The target did not respond. \value ChecksumMismatchError The checksum has detected a corrupted response. \value InvalidParametersError Invalid parameters were passed to a tag type specific function. \value ConnectionError Failed to connect to the target. \value NdefReadError Failed to read NDEF messages from the target. \value NdefWriteError Failed to write NDEF messages to the target. \value CommandError Failed to send a command to the target. \value TimeoutError The request could not be completed within the time specified in waitForRequestCompleted(). \value UnsupportedTargetError The target used is unsupported. As example this can occur on missing required entitlement and/or privacy settings from the client app.

Enumerator
NoError 
UnknownError 
UnsupportedError 
TargetOutOfRangeError 
NoResponseError 
ChecksumMismatchError 
InvalidParametersError 
ConnectionError 
NdefReadError 
NdefWriteError 
CommandError 
TimeoutError 
UnsupportedTargetError 

Definition at line 50 of file qnearfieldtarget.h.

◆ Type

This enum describes the type of tag the target is detected as.

\value ProprietaryTag An unidentified proprietary target tag. \value NfcTagType1 An NFC tag type 1 target. \value NfcTagType2 An NFC tag type 2 target. \value NfcTagType3 An NFC tag type 3 target. \value NfcTagType4 An NFC tag type 4 target. This value is used if the NfcTagType4 cannot be further refined by NfcTagType4A or NfcTagType4B below. \value NfcTagType4A An NFC tag type 4 target based on ISO/IEC 14443-3A. \value NfcTagType4B An NFC tag type 4 target based on ISO/IEC 14443-3B. \value MifareTag A Mifare target.

Enumerator
ProprietaryTag 
NfcTagType1 
NfcTagType2 
NfcTagType3 
NfcTagType4 
NfcTagType4A 
NfcTagType4B 
MifareTag 

Definition at line 29 of file qnearfieldtarget.h.

Constructor & Destructor Documentation

◆ QNearFieldTarget() [1/2]

QNearFieldTarget::QNearFieldTarget ( QObject * parent = nullptr)
explicit

Constructs a new near field target with parent.

Definition at line 218 of file qnearfieldtarget.cpp.

◆ ~QNearFieldTarget()

QNearFieldTarget::~QNearFieldTarget ( )

Destroys the near field target.

Definition at line 226 of file qnearfieldtarget.cpp.

◆ QNearFieldTarget() [2/2]

QNearFieldTarget::QNearFieldTarget ( QNearFieldTargetPrivate * backend,
QObject * parent = nullptr )
protected

Definition at line 393 of file qnearfieldtarget.cpp.

Member Function Documentation

◆ accessMethods()

QNearFieldTarget::AccessMethods QNearFieldTarget::accessMethods ( ) const

Returns the access methods supported by this near field target.

Definition at line 261 of file qnearfieldtarget.cpp.

◆ disconnect()

bool QNearFieldTarget::disconnect ( )
Since
5.9

Closes the connection to the target to enable communication with the target from a different instance. The connection will also be closed, when the QNearFieldTarget is destroyed. A connection to the target device is (re)created to process a command or read/write a NDEF messages.

Returns true only if an existing connection was successfully closed; otherwise returns false.

Definition at line 279 of file qnearfieldtarget.cpp.

◆ disconnected

void QNearFieldTarget::disconnected ( )
signal

This signal is emitted when the near field target moves out of proximity.

◆ error

void QNearFieldTarget::error ( QNearFieldTarget::Error error,
const QNearFieldTarget::RequestId & id )
signal

This signal is emitted when an error occurs while processing request id.

The error parameter describes the error.

◆ hasNdefMessage()

bool QNearFieldTarget::hasNdefMessage ( )

Returns true if at least one NDEF message is stored on the near field target; otherwise returns false.

Definition at line 290 of file qnearfieldtarget.cpp.

◆ maxCommandLength()

int QNearFieldTarget::maxCommandLength ( ) const
Since
5.9

Returns the maximum number of bytes that can be sent with sendCommand. 0 will be returned if the target does not support sending tag type specific commands.

See also
sendCommand()

Definition at line 340 of file qnearfieldtarget.cpp.

◆ ndefMessageRead

void QNearFieldTarget::ndefMessageRead ( const QNdefMessage & message)
signal

This signal is emitted when a complete NDEF message has been read from the target.

See also
readNdefMessages()

◆ readNdefMessages()

QNearFieldTarget::RequestId QNearFieldTarget::readNdefMessages ( )

Starts reading NDEF messages stored on the near field target.

Returns a request id which can be used to track the completion status of the request. An invalid request id will be returned if the target does not support reading NDEF messages.

An ndefMessageRead() signal will be emitted for each NDEF message. The requestCompleted() signal will be emitted was all NDEF messages have been read. The error() signal is emitted if an error occurs.

Note
An attempt to read an NDEF message from a tag, that is in INITIALIZED state as defined by NFC Forum, will fail with the \l NdefReadError, as the tag is formatted to support NDEF but does not contain a message yet.

Definition at line 310 of file qnearfieldtarget.cpp.

◆ requestCompleted

void QNearFieldTarget::requestCompleted ( const QNearFieldTarget::RequestId & id)
signal

This signal is emitted when a request id completes.

See also
sendCommand()

◆ requestResponse()

QVariant QNearFieldTarget::requestResponse ( const RequestId & id) const

Returns the decoded response for request id.

If the request is unknown or has not yet been completed an invalid QVariant is returned.

Definition at line 383 of file qnearfieldtarget.cpp.

◆ sendCommand()

QNearFieldTarget::RequestId QNearFieldTarget::sendCommand ( const QByteArray & command)

Sends command to the near field target.

Returns a request id which can be used to track the completion status of the request. An invalid request id will be returned if the target does not support sending tag type specific commands.

The requestCompleted() signal will be emitted on successful completion of the request; otherwise the error() signal will be emitted.

Once the request completes successfully the response can be retrieved from the requestResponse() function. The response of this request will be a QByteArray.

See also
requestCompleted(), waitForRequestCompleted()

Definition at line 360 of file qnearfieldtarget.cpp.

◆ type()

QNearFieldTarget::Type QNearFieldTarget::type ( ) const

Returns the type of tag type of this near field target.

Definition at line 251 of file qnearfieldtarget.cpp.

◆ uid()

QByteArray QNearFieldTarget::uid ( ) const

Returns the UID of the near field target.

Note
On iOS, this function returns an empty QByteArray for a near field target discovered using NdefAccess method.
See also
QNearFieldTarget::AccessMethod

Definition at line 241 of file qnearfieldtarget.cpp.

◆ waitForRequestCompleted()

bool QNearFieldTarget::waitForRequestCompleted ( const RequestId & id,
int msecs = 5000 )

Waits up to msecs milliseconds for the request id to complete.

Returns true if the request completes successfully and the requestCompeted() signal is emitted; otherwise returns false.

Definition at line 372 of file qnearfieldtarget.cpp.

◆ writeNdefMessages()

QNearFieldTarget::RequestId QNearFieldTarget::writeNdefMessages ( const QList< QNdefMessage > & messages)

Writes the NDEF messages in messages to the target.

Returns a request id which can be used to track the completion status of the request. An invalid request id will be returned if the target does not support reading NDEF messages.

The requestCompleted() signal will be emitted when the write operation completes successfully; otherwise the error() signal is emitted.

Definition at line 325 of file qnearfieldtarget.cpp.

Friends And Related Symbol Documentation

◆ QNearFieldManagerPrivateImpl

friend class QNearFieldManagerPrivateImpl
friend

Definition at line 26 of file qnearfieldtarget.h.


The documentation for this class was generated from the following files: