diff options
author | Tarja Sundqvist <tarja.sundqvist@qt.io> | 2024-01-22 23:05:16 +0200 |
---|---|---|
committer | Tarja Sundqvist <tarja.sundqvist@qt.io> | 2024-02-20 06:41:44 +0000 |
commit | e724de41a550dd67651942b6e28207e6e8f86f72 (patch) | |
tree | 6953c87e8fd4339bbb408ed949434d3d5de51c5c | |
parent | c41c1c113e6d93198d15b72406a8c6954a11051a (diff) | |
parent | ad17f20e332db9d45b64a13d1f80ab92934d22fa (diff) |
Merge remote-tracking branch 'origin/tqtc/lts-6.2.8' into tqtc/lts-6.2-opensource
Conflicts solved in a file:
dependencies.yaml
Change-Id: Iea485713daa99f508f3114f5537ee4529fded9fa
-rw-r--r-- | .cmake.conf | 2 | ||||
-rw-r--r-- | .qmake.conf | 2 | ||||
-rw-r--r-- | dependencies.yaml | 2 | ||||
-rw-r--r-- | src/serialport/doc/src/index.qdoc | 28 | ||||
-rw-r--r-- | src/serialport/qserialport.cpp | 51 | ||||
-rw-r--r-- | src/serialport/qwinoverlappedionotifier.cpp | 11 | ||||
-rw-r--r-- | tests/auto/qserialport/tst_qserialport.cpp | 40 |
7 files changed, 72 insertions, 64 deletions
diff --git a/.cmake.conf b/.cmake.conf index 07d90b8a..e62fae5e 100644 --- a/.cmake.conf +++ b/.cmake.conf @@ -1,2 +1,2 @@ -set(QT_REPO_MODULE_VERSION "6.2.7") +set(QT_REPO_MODULE_VERSION "6.2.8") set(QT_REPO_MODULE_PRERELEASE_VERSION_SEGMENT "") diff --git a/.qmake.conf b/.qmake.conf index 24e796fe..a0cf48b9 100644 --- a/.qmake.conf +++ b/.qmake.conf @@ -2,4 +2,4 @@ load(qt_build_config) DEFINES += QT_NO_FOREACH QT_NO_JAVA_STYLE_ITERATORS -MODULE_VERSION = 6.2.7 +MODULE_VERSION = 6.2.8 diff --git a/dependencies.yaml b/dependencies.yaml index fee29a45..f522f48e 100644 --- a/dependencies.yaml +++ b/dependencies.yaml @@ -1,4 +1,4 @@ dependencies: ../tqtc-qtbase: - ref: 694575a59b5370afc494fbf700eee8db1d1ec091 + ref: 67934c103800bae50c2ec1977758d40fa8e4e507 required: true diff --git a/src/serialport/doc/src/index.qdoc b/src/serialport/doc/src/index.qdoc index 2c349e44..54e25c90 100644 --- a/src/serialport/doc/src/index.qdoc +++ b/src/serialport/doc/src/index.qdoc @@ -31,9 +31,9 @@ \title Qt Serial Port \brief Provides an API to make serial programming simple and portable. - Qt Serial Port provides the basic functionality, which includes - configuring, I/O operations, getting and setting the control signals of the - RS-232 pinouts. + Qt Serial Port provides basic functionality for configuration, I/O + operations, and getting and setting the control signals of the RS-232 + pinouts. The following items are not supported by this module: \list @@ -43,27 +43,17 @@ \li Pinout signal change notification. \endlist - To use the serial port in your application, add the following include - statement: + \section1 Using the Module - \code - #include <QSerialPort> - \endcode + \include {module-use.qdocinc} {using the c++ api} - For information about available serial ports, use the following include - statement: + \section2 Building with Cmake - \code - #include <QSerialPortInfo> - \endcode + \include {module-use.qdocinc} {building with cmake} {SerialPort} - To use the module with cmake, use the \c{find_package()} command to locate - the needed module components in the \c{Qt6} package: - \include qtserialport-module-use.qdocinc cmakebuild + \section2 Building with qmake - To use the module for building with qmake, add the module as a value of the - \c QT variable in the project's .pro file: - \include qtserialport-module-use.qdocinc qmakebuild + \include {module-use.qdocinc} {building_with_qmake} {serialport} \section1 Module Evolution \l{Changes to Qt SerialPort} lists important changes in the module API diff --git a/src/serialport/qserialport.cpp b/src/serialport/qserialport.cpp index bc9504c2..c7d7e76d 100644 --- a/src/serialport/qserialport.cpp +++ b/src/serialport/qserialport.cpp @@ -101,6 +101,7 @@ void QSerialPortPrivate::setError(const QSerialPortErrorInfo &errorInfo) q->setErrorString(errorInfo.errorString); error.setValue(errorInfo.errorCode); + error.notify(); emit q->errorOccurred(error); } @@ -606,16 +607,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; } @@ -657,16 +658,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; } @@ -707,16 +708,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; } @@ -757,16 +758,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; } @@ -1177,21 +1178,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/src/serialport/qwinoverlappedionotifier.cpp b/src/serialport/qwinoverlappedionotifier.cpp index 1cce491e..dd3490d3 100644 --- a/src/serialport/qwinoverlappedionotifier.cpp +++ b/src/serialport/qwinoverlappedionotifier.cpp @@ -396,8 +396,8 @@ void QWinOverlappedIoNotifierPrivate::notify(DWORD numberOfBytes, DWORD errorCod Q_Q(QWinOverlappedIoNotifier); WaitForSingleObject(hResultsMutex, INFINITE); results.enqueue(IOResult(numberOfBytes, errorCode, overlapped)); - ReleaseMutex(hResultsMutex); ReleaseSemaphore(hSemaphore, 1, NULL); + ReleaseMutex(hResultsMutex); // Do not send a signal if we didn't process the previous one. // This is done to prevent soft memory leaks when working in a completely // synchronous way. @@ -417,6 +417,15 @@ void QWinOverlappedIoNotifierPrivate::_q_notified() WaitForSingleObject(hResultsMutex, INFINITE); QQueue<IOResult> values; results.swap(values); + // Decreasing the semaphore count to keep it in sync with the number + // of messages in queue. As ReleaseSemaphore does not accept negative + // values, this is sort of a recommended way to go: + // https://learn.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-releasesemaphore#remarks + int numToDecrease = values.size() - 1; + while (numToDecrease > 0) { + WaitForSingleObject(hSemaphore, 0); + --numToDecrease; + } ReleaseMutex(hResultsMutex); // 'q' can go out of scope if the user decides to close the serial port // while processing some answer. So we need to guard against that. diff --git a/tests/auto/qserialport/tst_qserialport.cpp b/tests/auto/qserialport/tst_qserialport.cpp index 268b8475..f700a178 100644 --- a/tests/auto/qserialport/tst_qserialport.cpp +++ b/tests/auto/qserialport/tst_qserialport.cpp @@ -1404,30 +1404,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.count(), 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) |