1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-18 08:54:15 +01:00

OP-1383 fixed Qt warning about QSerialPort parenting and thread ownership (seems to fix a crash on Windows when using serial connections)

This commit is contained in:
Philippe Renon 2014-07-14 22:04:47 +02:00
parent 6c8e4c8fad
commit 3e5240062a
2 changed files with 6 additions and 2 deletions

View File

@ -143,15 +143,17 @@ QIODevice *SerialConnection::openDevice(const QString &deviceName)
QList<QSerialPortInfo> ports = QSerialPortInfo::availablePorts();
foreach(QSerialPortInfo port, ports) {
if (port.portName() == deviceName) {
// don't specify a parent when constructing the QSerialPort as this object will be moved
// to a different thread later on (see telemetrymanager.cpp)
serialHandle = new QSerialPort(port);
// we need to handle port settings here...
qDebug() << "Serial telemetry running at " << m_config->speed();
serialHandle = new QSerialPort(port, this);
if (serialHandle->open(QIODevice::ReadWrite)) {
if (serialHandle->setBaudRate(m_config->speed().toInt())
&& serialHandle->setDataBits(QSerialPort::Data8)
&& serialHandle->setParity(QSerialPort::NoParity)
&& serialHandle->setStopBits(QSerialPort::OneStop)
&& serialHandle->setFlowControl(QSerialPort::NoFlowControl)) {
qDebug() << "Serial telemetry running at " << m_config->speed();
m_deviceOpened = true;
}
}

View File

@ -53,6 +53,8 @@ bool TelemetryManager::isConnected()
void TelemetryManager::start(QIODevice *dev)
{
device = dev;
// take ownership of the device (the why is not clear?)
device->moveToThread(Core::ICore::instance()->threadManager()->getRealTimeThread());
emit myStart();
}