Skip to content

Commit c0997dc

Browse files
committed
Backward compatible with Qt 5.12
1 parent daa78b1 commit c0997dc

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ You can download pre-built binaries in [release](https://github.com/wh201906/Ser
5050
### 1. Install depencencies
5151
```
5252
sudo apt-get update
53-
sudo apt-get install qt5-default libqt5serialport5 libqt5serialport5-dev
53+
sudo apt-get install qt5-default libqt5serialport5 libqt5serialport5-dev qtconnectivity5-dev
5454
```
5555
### 2. Get the source code
5656
```

src/connection.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,13 @@ void Connection::open()
272272
m_BLERxTxMode = BLE_2S2C;
273273
else
274274
m_BLERxTxMode = m_currBTArgument.RxCharacteristicUUID == m_currBTArgument.TxCharacteristicUUID ? BLE_1S1C : BLE_1S2C;
275+
if(m_BLEController != nullptr)
276+
m_BLEController->deleteLater();
277+
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
278+
m_BLEController = new QLowEnergyController(m_currBTArgument.deviceAddress, m_currBTArgument.localAdapterAddress);
279+
#else
275280
m_BLEController = QLowEnergyController::createCentral(m_currBTArgument.deviceAddress, m_currBTArgument.localAdapterAddress);
281+
#endif
276282
connect(m_BLEController, &QLowEnergyController::connected, m_BLEController, &QLowEnergyController::discoverServices);
277283
connect(m_BLEController, QOverload<QLowEnergyController::Error>::of(&QLowEnergyController::error), this, &Connection::onErrorOccurred);
278284
connect(m_BLEController, &QLowEnergyController::serviceDiscovered, this, &Connection::BLEC_onServiceDiscovered);
@@ -459,7 +465,11 @@ void Connection::updateSignalSlot()
459465
else if(m_type == TCP_Client)
460466
{
461467
m_lastReadyReadConn = connect(m_TCPSocket, &QIODevice::readyRead, this, &Connection::onReadyRead);
468+
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
469+
m_lastOnErrorConn = connect(m_TCPSocket, QOverload<QAbstractSocket::SocketError>::of(&QAbstractSocket::error), this, &Connection::onErrorOccurred);
470+
#else
462471
m_lastOnErrorConn = connect(m_TCPSocket, &QAbstractSocket::errorOccurred, this, &Connection::onErrorOccurred);
472+
#endif
463473
m_lastOnConnectedConn = connect(m_TCPSocket, &QAbstractSocket::connected, this, &Connection::onConnected);
464474
m_lastOnDisconnectedConn = connect(m_TCPSocket, &QAbstractSocket::disconnected, this, &Connection::onDisconnected);
465475
}
@@ -472,7 +482,11 @@ void Connection::updateSignalSlot()
472482
else if(m_type == UDP)
473483
{
474484
m_lastReadyReadConn = connect(m_UDPSocket, &QIODevice::readyRead, this, &Connection::onReadyRead);
485+
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
486+
m_lastOnErrorConn = connect(m_UDPSocket, QOverload<QAbstractSocket::SocketError>::of(&QAbstractSocket::error), this, &Connection::onErrorOccurred);
487+
#else
475488
m_lastOnErrorConn = connect(m_UDPSocket, &QAbstractSocket::errorOccurred, this, &Connection::onErrorOccurred);
489+
#endif
476490
m_lastOnConnectedConn = connect(m_UDPSocket, &QAbstractSocket::connected, this, &Connection::onConnected);
477491
m_lastOnDisconnectedConn = connect(m_UDPSocket, &QAbstractSocket::disconnected, this, &Connection::onDisconnected);
478492
}
@@ -849,7 +863,11 @@ void Connection::Server_onClientConnected()
849863
changeState(Connected);
850864
connect(socket, &QTcpSocket::readyRead, this, &Connection::onReadyRead);
851865
connect(socket, &QTcpSocket::disconnected, this, &Connection::Server_onClientDisconnected);
866+
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
867+
connect(socket, QOverload<QAbstractSocket::SocketError>::of(&QAbstractSocket::error), this, &Connection::onErrorOccurred);
868+
#else
852869
connect(socket, &QAbstractSocket::errorOccurred, this, &Connection::onErrorOccurred);
870+
#endif
853871
m_TCPConnectedClients.append(socket);
854872
m_TCPTxClients.append(socket);
855873
emit TCP_clientConnected();

src/devicetab.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,7 +1230,11 @@ void DeviceTab::on_BLEC_connectButton_clicked()
12301230
ui->BLEC_UUIDList->clear();
12311231
ui->BLEC_connectButton->setText(tr("Disconnect"));
12321232
ui->BLEC_currAddrLabel->setText(ui->BLEC_currAddrBox->currentText());
1233+
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
1234+
m_BLEController = new QLowEnergyController(QBluetoothAddress(ui->BLEC_currAddrBox->currentText()), QBluetoothAddress(ui->BLEC_adapterBox->currentData().toString()));
1235+
#else
12331236
m_BLEController = QLowEnergyController::createCentral(QBluetoothAddress(ui->BLEC_currAddrBox->currentText()), QBluetoothAddress(ui->BLEC_adapterBox->currentData().toString()));
1237+
#endif
12341238
connect(m_BLEController, &QLowEnergyController::connected, m_BLEController, &QLowEnergyController::discoverServices);
12351239
connect(m_BLEController, QOverload<QLowEnergyController::Error>::of(&QLowEnergyController::error), [ = ](QLowEnergyController::Error newError)
12361240
{

0 commit comments

Comments
 (0)