diff options
Diffstat (limited to 'examples/nfc/ndefeditor/nfctarget.cpp')
-rw-r--r-- | examples/nfc/ndefeditor/nfctarget.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/examples/nfc/ndefeditor/nfctarget.cpp b/examples/nfc/ndefeditor/nfctarget.cpp new file mode 100644 index 00000000..68b26df5 --- /dev/null +++ b/examples/nfc/ndefeditor/nfctarget.cpp @@ -0,0 +1,31 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +#include "nfctarget.h" + +NfcTarget::NfcTarget(QNearFieldTarget *target, QObject *parent) : QObject(parent), m_target(target) +{ + target->setParent(this); + + connect(target, &QNearFieldTarget::ndefMessageRead, this, &NfcTarget::ndefMessageRead); + connect(target, &QNearFieldTarget::requestCompleted, this, &NfcTarget::requestCompleted); + connect(target, &QNearFieldTarget::error, this, &NfcTarget::error); +} + +bool NfcTarget::readNdefMessages() +{ + if (m_target.isNull()) + return false; + + auto req = m_target->readNdefMessages(); + return req.isValid(); +} + +bool NfcTarget::writeNdefMessage(const QNdefMessage &message) +{ + if (m_target.isNull()) + return false; + + auto req = m_target->writeNdefMessages({ message }); + return req.isValid(); +} |