QNearFieldShareManager Class

The QNearFieldShareManager class manages all interactions related to sharing files and data over NFC. More...

Header: #include <QNearFieldShareManager>
qmake: QT += nfc
Since: Qt 5.3
Inherits: QObject

This class was introduced in Qt 5.3.

Public Types

enum ShareError { NoError, UnknownError, InvalidShareContentError, ShareCanceledError, ShareInterruptedError, …, SharePermissionDeniedError }
enum ShareMode { NoShare, NdefShare, FileShare }
flags ShareModes

Public Functions

QNearFieldShareManager(QObject *parent = nullptr)
virtual ~QNearFieldShareManager()
void setShareModes(ShareModes mode)
QNearFieldShareManager::ShareError shareError() const
QNearFieldShareManager::ShareModes shareModes() const

Signals

void error(QNearFieldShareManager::ShareError error)
void shareModesChanged(QNearFieldShareManager::ShareModes modes)
void targetDetected(QNearFieldShareTarget *shareTarget)

Static Public Members

QNearFieldShareManager::ShareModes supportedShareModes()

Detailed Description

Applications can share NDEF data or file content using NFC technology by tapping two NFC-enabled devices together. The QNearFieldShareManager provides a high level entry point to access this functionality.

The class allows both NDEF data and/or files to be shared between two devices by calling the setShareModes() method. This method specifies either an NDEF Data and/or a File transfer. The targetDetected() signal is emitted each time a share target is detected. A QNearFieldShareTarget pointer is passed with the signal, which can be used to share either an NDEF message or one or more files.

The process of sharing files via NFC involves other underlying communication transports such as Bluetooth or Wi-Fi Direct. It is implementation specific how and what type of transports are used to perform file transfer. The overall time taken to transfer content depends on the maximum speed of the transport used. Note that the process of sharing NDEF message/data does not require the use of other transports outside NFC.

If an error occurs, shareError() returns the error type.

Platforms that do not support both NDEF data and file content sharing modes can return the supported subset in the supportedShareModes() method. Applications that call setShareModes() with an unsupported mode will receive an error signal with a UnsupportedShareModeError.

Since sharing data over NFC is effectively a data pipe between two processes (one on the sender and one of the receiver), the application developer should only create a single instance of QNearFieldShareManager per application. This avoids the possibility that different parts of the same application attempt to all consume data transferred over NFC.

Member Type Documentation

enum QNearFieldShareManager::ShareError

This enum specifies the share error type.

ConstantValueDescription
QNearFieldShareManager::NoError0No error.
QNearFieldShareManager::UnknownError1Unknown or internal error occurred.
QNearFieldShareManager::InvalidShareContentError2Invalid content was provided for sharing.
QNearFieldShareManager::ShareCanceledError3Data or file sharing is canceled on the local or remote device.
QNearFieldShareManager::ShareInterruptedError4Data or file sharing is interrupted due to an I/O error.
QNearFieldShareManager::ShareRejectedError5Data or file sharing is rejected by the remote device.
QNearFieldShareManager::UnsupportedShareModeError6Data or file sharing is not supported by the share target.
QNearFieldShareManager::ShareAlreadyInProgressError7Data or file sharing is already in progress.
QNearFieldShareManager::SharePermissionDeniedError8File sharing is denied due to insufficient permission.

enum QNearFieldShareManager::ShareMode
flags QNearFieldShareManager::ShareModes

This enum specifies the content type to be shared.

ConstantValueDescription
QNearFieldShareManager::NoShare0x00No content is currently set to be shared.
QNearFieldShareManager::NdefShare0x01Share NDEF message with target.
QNearFieldShareManager::FileShare0x02Share file with target.

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

Member Function Documentation

QNearFieldShareManager::QNearFieldShareManager(QObject *parent = nullptr)

Constructs a new near field share manager with parent.

[signal] void QNearFieldShareManager::error(QNearFieldShareManager::ShareError error)

This signal is emitted whenever an error occurs related to a share request.

[signal] void QNearFieldShareManager::shareModesChanged(QNearFieldShareManager::ShareModes modes)

This signal is emitted whenever the share modes are changed.

[signal] void QNearFieldShareManager::targetDetected(QNearFieldShareTarget *shareTarget)

This signal is emitted whenever a shareTarget is detected. The shareTarget instance is owned by QNearFieldShareManager and must not be deleted by the application.

[virtual] QNearFieldShareManager::~QNearFieldShareManager()

Destroys the near field share manager.

void QNearFieldShareManager::setShareModes(ShareModes mode)

Initializes the NFC share mode to detect a QNearFieldShareTarget for data and/or file sharing. Calls to this method will overwrite previous share modes.

A shareModesChanged() signal will be emitted when share modes are different from previous modes. A targetDetected() signal will be emitted if a share target is detected.

See also shareModes().

QNearFieldShareManager::ShareError QNearFieldShareManager::shareError() const

Returns the error code of the error that occurred.

QNearFieldShareManager::ShareModes QNearFieldShareManager::shareModes() const

Returns which shared modes are set.

See also setShareModes().

[static] QNearFieldShareManager::ShareModes QNearFieldShareManager::supportedShareModes()

Returns the shared modes supported by NFC.