diff options
author | Ivan Solovev <ivan.solovev@qt.io> | 2022-12-06 12:49:48 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-12-07 13:11:37 +0000 |
commit | ee23371b2c9f7a225f50a23f49ee5641eda85761 (patch) | |
tree | 20c0c9b55ec88637e4a3ca35ae8ca4562e677595 | |
parent | 6ed88d12c6cdc66cdbe3a2d6638e67b88785383f (diff) |
Fix bindable properties
It looks like the bindable property implementation has changed after
the support for bindable properties was added to the module.
And because of the lack of testing in the CI, we failed to notice that
the tests started to fail.
This patch fixes the bindable properties implementation.
Fixes: QTBUG-109219
Change-Id: Id2677d6dfb74f26881c4ae73a844136fff160b02
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 71791866d3e167b89d8fc94162fa778e6b577ddb)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/serialport/qserialport.cpp | 51 | ||||
-rw-r--r-- | tests/auto/qserialport/tst_qserialport.cpp | 40 |
2 files changed, 50 insertions, 41 deletions
diff --git a/src/serialport/qserialport.cpp b/src/serialport/qserialport.cpp index 5eece08e..d4265b67 100644 --- a/src/serialport/qserialport.cpp +++ b/src/serialport/qserialport.cpp @@ -65,6 +65,7 @@ void QSerialPortPrivate::setError(const QSerialPortErrorInfo &errorInfo) q->setErrorString(errorInfo.errorString); error.setValue(errorInfo.errorCode); + error.notify(); emit q->errorOccurred(error); } @@ -570,16 +571,16 @@ qint32 QSerialPort::baudRate(Directions directions) const bool QSerialPort::setDataBits(DataBits dataBits) { Q_D(QSerialPort); - + d->dataBits.removeBindingUnlessInWrapper(); const auto currentDataBits = d->dataBits.value(); if (!isOpen() || d->setDataBits(dataBits)) { - d->dataBits.setValue(dataBits); - if (currentDataBits != dataBits) + d->dataBits.setValueBypassingBindings(dataBits); + if (currentDataBits != dataBits) { + d->dataBits.notify(); emit dataBitsChanged(dataBits); + } return true; } - d->dataBits.setValue(currentDataBits); // removes the binding if necessary, keep - return false; } @@ -621,16 +622,16 @@ QBindable<QSerialPort::DataBits> QSerialPort::bindableDataBits() bool QSerialPort::setParity(Parity parity) { Q_D(QSerialPort); - + d->parity.removeBindingUnlessInWrapper(); const auto currentParity = d->parity.value(); if (!isOpen() || d->setParity(parity)) { - d->parity.setValue(parity); - if (currentParity != parity) + d->parity.setValueBypassingBindings(parity); + if (currentParity != parity) { + d->parity.notify(); emit parityChanged(parity); + } return true; } - d->parity.setValue(currentParity); // removes the binding if necessary, keep - return false; } @@ -671,16 +672,16 @@ QBindable<QSerialPort::Parity> QSerialPort::bindableParity() bool QSerialPort::setStopBits(StopBits stopBits) { Q_D(QSerialPort); - + d->stopBits.removeBindingUnlessInWrapper(); const auto currentStopBits = d->stopBits.value(); if (!isOpen() || d->setStopBits(stopBits)) { - d->stopBits.setValue(stopBits); - if (currentStopBits != stopBits) + d->stopBits.setValueBypassingBindings(stopBits); + if (currentStopBits != stopBits) { + d->stopBits.notify(); emit stopBitsChanged(stopBits); + } return true; } - d->stopBits.setValue(currentStopBits); // removes the binding if necessary, keep - return false; } @@ -721,16 +722,16 @@ QBindable<bool> QSerialPort::bindableStopBits() bool QSerialPort::setFlowControl(FlowControl flowControl) { Q_D(QSerialPort); - + d->flowControl.removeBindingUnlessInWrapper(); const auto currentFlowControl = d->flowControl.value(); if (!isOpen() || d->setFlowControl(flowControl)) { - d->flowControl.setValue(flowControl); - if (currentFlowControl != flowControl) + d->flowControl.setValueBypassingBindings(flowControl); + if (currentFlowControl != flowControl) { + d->flowControl.notify(); emit flowControlChanged(flowControl); + } return true; } - d->flowControl.setValue(currentFlowControl); // removes the binding if necessary, keep - return false; } @@ -1141,21 +1142,21 @@ bool QSerialPort::waitForBytesWritten(int msecs) bool QSerialPort::setBreakEnabled(bool set) { Q_D(QSerialPort); - + d->isBreakEnabled.removeBindingUnlessInWrapper(); const auto currentSet = d->isBreakEnabled.value(); if (isOpen()) { if (d->setBreakEnabled(set)) { - d->isBreakEnabled.setValue(set); - if (currentSet != set) + d->isBreakEnabled.setValueBypassingBindings(set); + if (currentSet != set) { + d->isBreakEnabled.notify(); emit breakEnabledChanged(set); + } return true; } } else { d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError)); qWarning("%s: device not open", Q_FUNC_INFO); } - d->isBreakEnabled.setValue(currentSet); // removes the binding if necessary, keep - return false; } diff --git a/tests/auto/qserialport/tst_qserialport.cpp b/tests/auto/qserialport/tst_qserialport.cpp index 9613208b..a7eeb147 100644 --- a/tests/auto/qserialport/tst_qserialport.cpp +++ b/tests/auto/qserialport/tst_qserialport.cpp @@ -1379,30 +1379,38 @@ void tst_QSerialPort::bindingsAndProperties() QCOMPARE(errorChangedSpy.at(0).value(0).toInt(), QSerialPort::SerialPortError::NoError); sp.setPortName(m_receiverPortName); - sp.open(QIODevice::ReadOnly); + const bool portOpened = sp.open(QIODevice::ReadOnly); // -- break enabled - QProperty<bool> beProp(false); - QCOMPARE(beProp.value(), false); + if (portOpened) { + QProperty<bool> beProp(false); + QCOMPARE(beProp.value(), false); - sp.bindableIsBreakEnabled().setBinding(Qt::makePropertyBinding(beProp)); - QCOMPARE(sp.isBreakEnabled(), false); + sp.bindableIsBreakEnabled().setBinding(Qt::makePropertyBinding(beProp)); + QCOMPARE(sp.isBreakEnabled(), false); - const QSignalSpy breakEnabledChangedSpy(&sp, &QSerialPort::breakEnabledChanged); + const QSignalSpy breakEnabledChangedSpy(&sp, &QSerialPort::breakEnabledChanged); - beProp = true; - QCOMPARE(sp.isBreakEnabled(), true); - QCOMPARE(breakEnabledChangedSpy.size(), 1); - QCOMPARE(breakEnabledChangedSpy.at(0).value(0).toBool(), true); + beProp = true; + QCOMPARE(sp.isBreakEnabled(), true); + QCOMPARE(breakEnabledChangedSpy.size(), 1); + QCOMPARE(breakEnabledChangedSpy.at(0).value(0).toBool(), true); - beProp.setBinding(sp.bindableIsBreakEnabled().makeBinding()); - sp.setBreakEnabled(false); - QCOMPARE(beProp.value(), false); + beProp.setBinding(sp.bindableIsBreakEnabled().makeBinding()); + sp.setBreakEnabled(false); + QCOMPARE(beProp.value(), false); - beProp.setBinding([&] { return sp.isBreakEnabled(); }); - sp.setBreakEnabled(true); - QCOMPARE(beProp.value(), true); + beProp.setBinding([&] { return sp.isBreakEnabled(); }); + sp.setBreakEnabled(true); + QCOMPARE(beProp.value(), true); + } else { + // setting isBreakEnabled() will return false and raise an error + const auto currErrorCount = errorChangedSpy.size(); + sp.setBreakEnabled(true); + QCOMPARE(errorProp.value(), QSerialPort::SerialPortError::NotOpenError); + QCOMPARE(errorChangedSpy.size(), currErrorCount + 1); + } } QTEST_MAIN(tst_QSerialPort) |