QtMobility Reference Documentation

QNearFieldTarget Class Reference

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

 #include <QNearFieldTarget>

Inherits: QObject.

Inherited by: QNearFieldTagType1, QNearFieldTagType2, QNearFieldTagType3, and QNearFieldTagType4.

This class was introduced in Qt Mobility 1.2.

Public Types

class RequestId
enum AccessMethod { NdefAccess, TagTypeSpecificAccess, LlcpAccess }
flags AccessMethods
enum Error { NoError, UnknownError, UnsupportedError, TargetOutOfRangeError, ..., NdefWriteError }
enum Type { AnyTarget, ProprietaryTag, NfcTagType1, NfcTagType2, ..., NfcForumDevice }

Public Functions

QNearFieldTarget ( QObject * parent = 0 )
virtual ~QNearFieldTarget ()
virtual AccessMethods accessMethods () const = 0
virtual bool hasNdefMessage ()
bool isProcessingCommand () const
virtual RequestId readNdefMessages ()
QVariant requestResponse ( const RequestId & id )
virtual RequestId sendCommand ( const QByteArray & command )
virtual RequestId sendCommands ( const QList<QByteArray> & commands )
void setResponseForRequest ( const QNearFieldTarget::RequestId & id, const QVariant & response, bool emitRequestCompleted = true )
virtual Type type () const = 0
virtual QByteArray uid () const = 0
virtual QUrl url () const
virtual bool waitForRequestCompleted ( const RequestId & id, int msecs = 5000 )
virtual RequestId writeNdefMessages ( const QList<QNdefMessage> & messages )
  • 29 public functions inherited from QObject

Signals

void disconnected ()
void error ( QNearFieldTarget::Error error, const QNearFieldTarget::RequestId & id )
void ndefMessageRead ( const QNdefMessage & message )
void ndefMessagesWritten ()
void requestCompleted ( const QNearFieldTarget::RequestId & id )

Protected Functions

virtual bool handleResponse ( const QNearFieldTarget::RequestId & id, const QByteArray & response )
  • 7 protected functions inherited from QObject

Related Non-Members

quint16 qNfcChecksum ( const char * data, uint len )

Additional Inherited Members

  • 1 property inherited from QObject
  • 1 public slot inherited from QObject
  • 1 public variable inherited from QObject
  • 4 static public members inherited from QObject
  • 2 protected variables inherited from QObject

Detailed Description

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

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. sendCommands() can be used to send multiple proprietary commands to the target and retrieve all of the responses.

If the target supports LlcpAccess, the QLlcpSocket class can be used to connected to a service provided by the target.

Member Type Documentation

enum QNearFieldTarget::AccessMethod
flags QNearFieldTarget::AccessMethods

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

ConstantValueDescription
QNearFieldTarget::NdefAccess0The target supports reading and writing NDEF messages using readNdefMessages() and writeNdefMessages().
QNearFieldTarget::TagTypeSpecificAccess1The target supports sending tag type specific commands using sendCommand() and sendCommands().
QNearFieldTarget::LlcpAccess2The target supports peer-to-peer LLCP communication.

The AccessMethods type is a typedef for QFlags<AccessMethod>. It stores an OR combination of AccessMethod values.

enum QNearFieldTarget::Error

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

ConstantValueDescription
QNearFieldTarget::NoError0No error has occurred.
QNearFieldTarget::UnknownError1An unidentified error occurred.
QNearFieldTarget::UnsupportedError2The requested operation is unsupported by this near field target.
QNearFieldTarget::TargetOutOfRangeError3The target is no longer within range.
QNearFieldTarget::NoResponseError4The target did not respond.
QNearFieldTarget::ChecksumMismatchError5The checksum has detected a corrupted response.
QNearFieldTarget::InvalidParametersError6Invalid parameters were passed to a tag type specific function.
QNearFieldTarget::NdefReadError7Failed to read NDEF messages from the target.
QNearFieldTarget::NdefWriteError8Failed to write NDEF messages to the target.

enum QNearFieldTarget::Type

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

ConstantValueDescription
QNearFieldTarget::AnyTarget0This value is only used when registering handlers to indicate that any compatible target can be used.
QNearFieldTarget::ProprietaryTag1An unidentified proprietary target tag.
QNearFieldTarget::NfcTagType12An NFC tag type 1 target.
QNearFieldTarget::NfcTagType23An NFC tag type 2 target.
QNearFieldTarget::NfcTagType34An NFC tag type 3 target.
QNearFieldTarget::NfcTagType45An NFC tag type 4 target.
QNearFieldTarget::MifareTag6A Mifare target.
QNearFieldTarget::NfcForumDevice7An NFC Forum device target.

Member Function Documentation

QNearFieldTarget::QNearFieldTarget ( QObject * parent = 0 )

Constructs a new near field target with parent.

QNearFieldTarget::~QNearFieldTarget () [virtual]

Destroys the near field target.

AccessMethods QNearFieldTarget::accessMethods () const [pure virtual]

Returns the access methods support by this near field target.

void QNearFieldTarget::disconnected () [signal]

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

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.

bool QNearFieldTarget::handleResponse ( const QNearFieldTarget::RequestId & id, const QByteArray & response ) [virtual protected]

Handles the response received for the request id. Returns true if the response is handled; otherwise returns false.

Classes reimplementing this virtual function should call the base class implementation to ensure that requests initiated by those classes are handled correctly.

The default implementation stores the response such that it can be retrieved by requestResponse().

bool QNearFieldTarget::hasNdefMessage () [virtual]

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

bool QNearFieldTarget::isProcessingCommand () const

Returns true if the target is processing commands; otherwise returns false.

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().

void QNearFieldTarget::ndefMessagesWritten () [signal]

This signal is emitted when NDEF messages have been successfully written to the target.

See also writeNdefMessages().

RequestId QNearFieldTarget::readNdefMessages () [virtual]

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: Symbian^3 and Harmattan only support read one NDEF message.

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

This signal is emitted when a request id completes.

See also sendCommand().

QVariant QNearFieldTarget::requestResponse ( const RequestId & id )

Returns the decoded response for request id. If the request is unknown or has not yet been completed an invalid QVariant is returned.

RequestId QNearFieldTarget::sendCommand ( const QByteArray & command ) [virtual]

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() and waitForRequestCompleted().

RequestId QNearFieldTarget::sendCommands ( const QList<QByteArray> & commands ) [virtual]

Sends multiple commands 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.

If all commands complete successfully the requestCompleted() signal will be emitted; otherwise the error() signal will be emitted. If a command fails succeeding commands from this call will not be processed.

Once the request completes the response for successfully completed requests can be retrieved from the requestResponse() function. The response of this request will be a QList<QByteArray>.

See also requestCompleted() and waitForRequestCompleted().

void QNearFieldTarget::setResponseForRequest ( const QNearFieldTarget::RequestId & id, const QVariant & response, bool emitRequestCompleted = true )

Sets the decoded response for request id to response. If emitRequestCompleted is true the requestCompleted() signal will be emitted for id; otherwise no signal will be emitted.

See also requestResponse().

Type QNearFieldTarget::type () const [pure virtual]

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

QByteArray QNearFieldTarget::uid () const [pure virtual]

Returns the UID of the near field target.

QUrl QNearFieldTarget::url () const [virtual]

Returns the URL of the near field target.

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

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.

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

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 ndefMessagesWritten() signal will be emitted when the write operation completes successfully; otherwise the error() signal is emitted.

Note: Symbian^3 and Harmattan only support writing one NDEF message. Only the first NDEF message in the list will be written, others are silently dropped.

Related Non-Members

quint16 qNfcChecksum ( const char * data, uint len )

Returns the NFC checksum of the first len bytes of data.

X

Thank you for giving your feedback.

Make sure it is related to this specific page. For more general bugs and requests, please use the Qt Bug Tracker.