/** * Method called when the user clicks the "Connect" button */ bool ConnectionManager::connectDevice(DevListItem device) { if (!device.connection) { emit connectDeviceFailed(&device); return false; } QIODevice *io_dev = device.connection->openDevice(device.device); if (!io_dev) { emit connectDeviceFailed(&device); return false; } io_dev->open(QIODevice::ReadWrite); // check if opening the device worked if (!io_dev->isOpen()) { emit connectDeviceFailed(&device); return false; } // The device is connected make it the one selected on the dropbox for(int x = 0; x < m_availableDevList->count(); ++x) { if(device.getConName() == m_availableDevList->itemData(x,Qt::ToolTipRole).toString()) m_availableDevList->setCurrentIndex(x); } // we appear to have connected to the device OK // remember the connection/device details m_connectionDevice = device; m_ioDev = io_dev; connect(m_connectionDevice.connection, SIGNAL(destroyed(QObject *)), this, SLOT(onConnectionDestroyed(QObject *)), Qt::QueuedConnection); // signal interested plugins that we connected to the device emit deviceConnected(io_dev); m_connectBtn->setText("Disconnect"); m_availableDevList->setEnabled(false); // tell the monitorwidget we're conneced m_monitorWidget->connected(); return true; }
foreach (DevListItem d, m_devList) { if (d.getConName() == devName) return d; }