NfcReceiver.cpp Example File
nfcreceiver/src/NfcReceiver.cpp
#include "NfcReceiver.hpp"
#include <bb/system/InvokeManager.hpp>
#include <QtNfcSubset/qndefmessage.h>
NfcReceiver::NfcReceiver(QObject *parent)
: QObject(parent)
, m_messageRecords(new bb::cascades::QVariantListDataModel())
{
m_messageRecords->setParent(this);
bb::system::InvokeManager *invokeManager = new bb::system::InvokeManager(this);
bool ok = connect(invokeManager, SIGNAL(invoked(const bb::system::InvokeRequest&)),
this, SLOT(receivedInvokeTarget(const bb::system::InvokeRequest&)));
Q_ASSERT(ok);
Q_UNUSED(ok);
}
void NfcReceiver::receivedInvokeTarget(const bb::system::InvokeRequest& request)
{
const QByteArray data = request.data();
const QtMobilitySubset::QNdefMessage ndefMessage = QtMobilitySubset::QNdefMessage::fromByteArray(data);
m_messageRecords->clear();
for (int i = 0; i < ndefMessage.size(); ++i) {
const QtMobilitySubset::QNdefRecord record = ndefMessage.at(i);
QVariantMap entry;
entry["tnfType"] = record.typeNameFormat();
entry["recordType"] = QString::fromLatin1(record.type());
entry["payload"] = QString::fromLatin1(record.payload());
entry["hexPayload"] = QString::fromLatin1(record.payload().toHex());
m_messageRecords->append(entry);
}
emit messageReceived();
}
bb::cascades::DataModel* NfcReceiver::messageRecords() const
{
return m_messageRecords;
}