// // Created by robin on 10/1/17. // #include "MainWindow.h" #include #include MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , m_pUi(new Ui_MainWindow()) { m_pUi->setupUi(this); refreshReaders(); } bool MainWindow::initLibNfc() { if (!m_pLibNfc) { m_pLibNfc.reset(new LibNfcBusiness()); auto initResult = m_pLibNfc->init(); if (!initResult) { showError(initResult); return false; } } return true; } void MainWindow::refreshReaders() { if (!initLibNfc()) { return; } m_pUi->pComboReaders->clear(); LibNfcOperation::runOperation>>(m_pLibNfc, [](QSharedPointer libNfc) { return (Result>>) libNfc->getDevices(); }, [this](Result>> devicesResult) { m_devices = devicesResult.getData(); for (auto& device : m_devices) { m_pUi->pComboReaders->addItem(device->getConnStr().c_str()); } }); // auto devicesResult = m_pLibNfc->getDevices(); // if (!devicesResult) { // showError(devicesResult); // return; // } // // m_devices = devicesResult.getData(); // for (auto& device : m_devices) { // m_pUi->pComboReaders->addItem(device->getConnStr().c_str()); // } } template void MainWindow::showError(Result result) { result.print(); QMessageBox::critical(this, "LibNfc Error", QString("LibNfc error: %1").arg(result.getError().c_str())); }