summaryrefslogtreecommitdiffstats
path: root/examples/nfc/ndefeditor/doc/src/ndefeditor.qdoc
blob: 975ee9bea2f761171344e67078e645891058a9d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/****************************************************************************
**
** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt local connectivity modules.
**
** $QT_BEGIN_LICENSE:FDL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file. Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
** $QT_END_LICENSE$
**
****************************************************************************/

/*!
\example ndefeditor
\title NDEF Editor Example
\brief An example of reading and writing NFC Data Exchange Format (NDEF) messages to NFC Forum Tags.

The NDEF Editor example reads and writes NFC Data Exchange Format
(NDEF) messages to NFC Forum Tags. NDEF messages can be composed by
adding records of supported types. Additionally, NDEF messages can be
loaded/saved from/into a file located in the file system of the
device where the application is running.

\image ndefeditor.png

\section1 NFC Tag detection

The \c MainWindow class is able to detect if an NFC Tag is in the range
for read/write operations. It can also detect if the connection has been
lost. This is achieved by connecting the \c MainWindow class private
handlers to the \l QNearFieldManager::targetDetected and
\l QNearFieldManager::targetLost signals.

\snippet ndefeditor/mainwindow.cpp QNearFieldManager init

When \e Read or \e Write button is pressed, the detection of NFC tags is started
by calling the \l QNearFieldManager::startTargetDetection method.

\snippet ndefeditor/mainwindow.cpp QNearFieldManager start detection

Once the target is detected, the \c MainWindow connects the following
signals to its internal private slots:
\l QNearFieldTarget::ndefMessageRead, \l QNearFieldTarget::NdefReadError,
\l QNearFieldTarget::requestCompleted,
\l QNearFieldTarget::NdefWriteError and \l {QNearFieldTarget::error}.

\snippet ndefeditor/mainwindow.cpp QNearFieldTarget detected

If during the process of reading or writing to an NFC Tag the
connection is lost, the \c MainWindow reacts to this event by
scheduling the target deletion (using \l QObject::deleteLater).

\snippet ndefeditor/mainwindow.cpp QNearFieldTarget lost

\section1 Record creation

The main window of the NDEF Editor example manages the composition and
creation of NFC records. The UI contains a \l QScrollArea, which is used to
dynamically add the record editors. The following methods of the \c MainWindow
class provide an interface towards each of the record editing classes managing
the different types of records.

\snippet ndefeditor/mainwindow.h 0

The following sections explain each of the record editing classes.

\section1 Record editing classes

\section2 TextRecordEditor

The \c TextRecordEditor is a \l QWidget that allows to edit the contents of the
NDEF Text record. A new instance of this class is created for each text record.

\snippet ndefeditor/textrecordeditor.h 0

\section2 UriRecordEditor

The \c UriRecordEditor is a \l QWidget that allows to edit the contents of the
NDEF Uri record. A new instance of this class is created for each uri record.

\snippet ndefeditor/urirecordeditor.h 0

\section2 MimeImageRecordEditor

The \c MimeImageRecordEditor is a \l QWidget that allows to edit the contents of
the NDEF MIME record. In this example MIME record can be used to store an icon.
A new instance of this class is created for each MIME record.

\snippet ndefeditor/mimeimagerecordeditor.h 0

\include examples-run.qdocinc

\sa {Qt NFC}
*/