diff options
84 files changed, 491 insertions, 1289 deletions
diff --git a/.cmake.conf b/.cmake.conf index 05b80d3a..dc1d7a92 100644 --- a/.cmake.conf +++ b/.cmake.conf @@ -1,4 +1,5 @@ -set(QT_REPO_MODULE_VERSION "6.5.0") +set(QT_REPO_MODULE_VERSION "6.8.0") set(QT_REPO_MODULE_PRERELEASE_VERSION_SEGMENT "alpha1") -# Use cpp-based syncqt -set(QT_USE_SYNCQT_CPP TRUE) +set(QT_EXTRA_INTERNAL_TARGET_DEFINES "QT_NO_AS_CONST=1") +list(APPEND QT_EXTRA_INTERNAL_TARGET_DEFINES "QT_NO_FOREACH=1") +list(APPEND QT_EXTRA_INTERNAL_TARGET_DEFINES "QT_NO_CONTEXTLESS_CONNECT=1") @@ -5,7 +5,7 @@ Makefile *.o *.a moc_*.cpp -*.pro.user +*.pro.user* *.moc lib*.so lib*.so.* @@ -21,4 +21,4 @@ Makefile.Release .vs CMakeSettings.json out/* -CMakeLists.txt.user +CMakeLists.txt.user* diff --git a/CMakeLists.txt b/CMakeLists.txt index 45190e34..777a0420 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,7 @@ set(QT_NO_INTERNAL_COMPATIBILITY_FUNCTIONS TRUE) find_package(Qt6 ${PROJECT_VERSION} CONFIG REQUIRED COMPONENTS BuildInternals Core) find_package(Qt6 ${PROJECT_VERSION} CONFIG OPTIONAL_COMPONENTS Gui Widgets) +qt_internal_project_setup() if(INTEGRITY) message(NOTICE "Skipping the build as the condition \"NOT INTEGRITY\" is not met.") diff --git a/coin/axivion/ci_config_linux.json b/coin/axivion/ci_config_linux.json new file mode 100644 index 00000000..b7ae35f2 --- /dev/null +++ b/coin/axivion/ci_config_linux.json @@ -0,0 +1,40 @@ +{ + "Project": { + "BuildSystemIntegration": { + "child_order": [ + "GCCSetup", + "CMake", + "LinkLibraries" + ] + }, + "CMake": { + "_active": true, + "_copy_from": "CMakeIntegration", + "build_environment": {}, + "build_options": "-j4", + "generate_options": "--fresh", + "generator": "Ninja" + }, + "GCCSetup": { + "_active": true, + "_copy_from": "Command", + "build_command": "gccsetup --cc gcc --cxx g++ --config ../../../axivion/" + }, + "LinkLibraries": { + "_active": true, + "_copy_from": "AxivionLinker", + "input_files": [ + "build/lib/lib*.so*.ir" + ], + "ir": "build/$(env:TESTED_MODULE_COIN).ir" + } + }, + "_Format": "1.0", + "_Version": "7.6.2", + "_VersionNum": [ + 7, + 6, + 2, + 12725 + ] +} diff --git a/conanfile.py b/conanfile.py deleted file mode 100644 index b8ad8f90..00000000 --- a/conanfile.py +++ /dev/null @@ -1,31 +0,0 @@ -# Copyright (C) 2021 The Qt Company Ltd. -# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 - -from conans import ConanFile -import re -from pathlib import Path - - -def _parse_qt_version_by_key(key: str) -> str: - with open(Path(__file__).parent.resolve() / ".cmake.conf") as f: - m = re.search(fr'{key} .*"(.*)"', f.read()) - return m.group(1) if m else "" - - -def _get_qt_minor_version() -> str: - return ".".join(_parse_qt_version_by_key("QT_REPO_MODULE_VERSION").split(".")[:2]) - - -class QtSerialPort(ConanFile): - name = "qtserialport" - license = "LGPL-3.0, GPL-2.0+, Commercial Qt License Agreement" - author = "The Qt Company <https://www.qt.io/contact-us>" - url = "https://code.qt.io/cgit/qt/qtserialport.git" - description = "Qt Serialport support." - topics = "qt", "qt6", "serialport", "serial communication interface" - settings = "os", "compiler", "arch", "build_type" - # for referencing the version number and prerelease tag and dependencies info - exports = ".cmake.conf", "dependencies.yaml" - exports_sources = "*", "!conan*.*" - python_requires = f"qt-conan-common/{_get_qt_minor_version()}@qt/everywhere" - python_requires_extend = "qt-conan-common.QtLeafModule" diff --git a/dependencies.yaml b/dependencies.yaml index cffab768..06312fa0 100644 --- a/dependencies.yaml +++ b/dependencies.yaml @@ -1,4 +1,4 @@ dependencies: ../qtbase: - ref: 01780d753e960133ae0110c6ef4292fbd2ea306c + ref: e7362764d4931f255d2377462df8ac7a0d4e7c84 required: true diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 0b3097bd..8eb9e9e1 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,5 +1,5 @@ # Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause qt_examples_build_begin(EXTERNAL_BUILD) diff --git a/examples/serialport/CMakeLists.txt b/examples/serialport/CMakeLists.txt index aa16ae74..21bd2743 100644 --- a/examples/serialport/CMakeLists.txt +++ b/examples/serialport/CMakeLists.txt @@ -1,16 +1,8 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause +# Copyright (C) 2023 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -qt_internal_add_example(cenumerator) -qt_internal_add_example(creaderasync) -qt_internal_add_example(creadersync) -qt_internal_add_example(cwriterasync) -qt_internal_add_example(cwritersync) -if((((NOT QT.widgets.name_ISEMPTY)))) - qt_internal_add_example(enumerator) +if(TARGET Qt::Widgets) qt_internal_add_example(terminal) qt_internal_add_example(blockingsender) qt_internal_add_example(blockingreceiver) - qt_internal_add_example(sender) - qt_internal_add_example(receiver) endif() diff --git a/examples/serialport/blockingreceiver/CMakeLists.txt b/examples/serialport/blockingreceiver/CMakeLists.txt index e835de82..25088dd5 100644 --- a/examples/serialport/blockingreceiver/CMakeLists.txt +++ b/examples/serialport/blockingreceiver/CMakeLists.txt @@ -1,11 +1,9 @@ # Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause cmake_minimum_required(VERSION 3.16) project(blockingreceiver LANGUAGES CXX) -set(CMAKE_AUTOMOC ON) - if(NOT DEFINED INSTALL_EXAMPLESDIR) set(INSTALL_EXAMPLESDIR "examples") endif() @@ -14,6 +12,8 @@ set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/serialport/blockingreceiver") find_package(Qt6 REQUIRED COMPONENTS Core Gui SerialPort Widgets) +qt_standard_project_setup() + qt_add_executable(blockingreceiver dialog.cpp dialog.h main.cpp diff --git a/examples/serialport/blockingreceiver/receiverthread.cpp b/examples/serialport/blockingreceiver/receiverthread.cpp index 6d7f24e5..a35aadc7 100644 --- a/examples/serialport/blockingreceiver/receiverthread.cpp +++ b/examples/serialport/blockingreceiver/receiverthread.cpp @@ -56,7 +56,10 @@ void ReceiverThread::run() while (!m_quit) { //![6] //! [7] - if (currentPortNameChanged) { + if (currentPortName.isEmpty()) { + emit error(tr("Port not set")); + return; + } else if (currentPortNameChanged) { serial.close(); serial.setPortName(currentPortName); diff --git a/examples/serialport/blockingsender/CMakeLists.txt b/examples/serialport/blockingsender/CMakeLists.txt index 265a728f..e7f4ade3 100644 --- a/examples/serialport/blockingsender/CMakeLists.txt +++ b/examples/serialport/blockingsender/CMakeLists.txt @@ -1,11 +1,9 @@ # Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause cmake_minimum_required(VERSION 3.16) project(blockingsender LANGUAGES CXX) -set(CMAKE_AUTOMOC ON) - if(NOT DEFINED INSTALL_EXAMPLESDIR) set(INSTALL_EXAMPLESDIR "examples") endif() @@ -14,6 +12,8 @@ set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/serialport/blockingsender") find_package(Qt6 REQUIRED COMPONENTS Core Gui SerialPort Widgets) +qt_standard_project_setup() + qt_add_executable(blockingsender dialog.cpp dialog.h main.cpp diff --git a/examples/serialport/cenumerator/CMakeLists.txt b/examples/serialport/cenumerator/CMakeLists.txt deleted file mode 100644 index 3aa713fd..00000000 --- a/examples/serialport/cenumerator/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(cenumerator LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/serialport/cenumerator") - -find_package(Qt6 REQUIRED COMPONENTS Core SerialPort) - -qt_add_executable(cenumerator - main.cpp -) - -set_target_properties(cenumerator PROPERTIES - WIN32_EXECUTABLE FALSE - MACOSX_BUNDLE FALSE -) - -target_link_libraries(cenumerator PRIVATE - Qt::Core - Qt::SerialPort -) - -install(TARGETS cenumerator - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/serialport/cenumerator/cenumerator.pro b/examples/serialport/cenumerator/cenumerator.pro deleted file mode 100644 index 75a43e36..00000000 --- a/examples/serialport/cenumerator/cenumerator.pro +++ /dev/null @@ -1,14 +0,0 @@ -QT = core -QT += serialport - -CONFIG += console -CONFIG -= app_bundle - -TARGET = cenumerator -TEMPLATE = app - -SOURCES += \ - main.cpp - -target.path = $$[QT_INSTALL_EXAMPLES]/serialport/cenumerator -INSTALLS += target diff --git a/examples/serialport/cenumerator/main.cpp b/examples/serialport/cenumerator/main.cpp deleted file mode 100644 index fc8fd9b3..00000000 --- a/examples/serialport/cenumerator/main.cpp +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (C) 2012 Laszlo Papp <lpapp@kde.org> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#include <QCoreApplication> -#include <QSerialPortInfo> -#include <QTextStream> - -int main(int argc, char *argv[]) -{ - QCoreApplication coreApplication(argc, argv); - QTextStream out(stdout); - const auto serialPortInfos = QSerialPortInfo::availablePorts(); - - out << "Total number of ports available: " << serialPortInfos.count() << Qt::endl; - - const QStringView blankString = u"N/A"; - - for (const QSerialPortInfo &serialPortInfo : serialPortInfos) { - const QStringView description = serialPortInfo.description(); - const QStringView manufacturer = serialPortInfo.manufacturer(); - const QStringView serialNumber = serialPortInfo.serialNumber(); - - out << Qt::endl - << "Port: " << serialPortInfo.portName() << Qt::endl - << "Location: " << serialPortInfo.systemLocation() << Qt::endl - << "Description: " << (!description.isEmpty() ? description : blankString) << Qt::endl - << "Manufacturer: " << (!manufacturer.isEmpty() ? manufacturer : blankString) << Qt::endl - << "Serial number: " << (!serialNumber.isEmpty() ? serialNumber : blankString) << Qt::endl - << "Vendor Identifier: " << (serialPortInfo.hasVendorIdentifier() - ? QByteArray::number(serialPortInfo.vendorIdentifier(), 16) - : blankString.toLatin1()) << Qt::endl - << "Product Identifier: " << (serialPortInfo.hasProductIdentifier() - ? QByteArray::number(serialPortInfo.productIdentifier(), 16) - : blankString.toLatin1()) << Qt::endl; - } - - return 0; -} diff --git a/examples/serialport/creaderasync/CMakeLists.txt b/examples/serialport/creaderasync/CMakeLists.txt deleted file mode 100644 index b60dbab3..00000000 --- a/examples/serialport/creaderasync/CMakeLists.txt +++ /dev/null @@ -1,36 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(creaderasync LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/serialport/creaderasync") - -find_package(Qt6 REQUIRED COMPONENTS Core SerialPort) - -qt_add_executable(creaderasync - main.cpp - serialportreader.cpp serialportreader.h -) - -set_target_properties(creaderasync PROPERTIES - WIN32_EXECUTABLE FALSE - MACOSX_BUNDLE FALSE -) - -target_link_libraries(creaderasync PRIVATE - Qt::Core - Qt::SerialPort -) - -install(TARGETS creaderasync - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/serialport/creaderasync/creaderasync.pro b/examples/serialport/creaderasync/creaderasync.pro deleted file mode 100644 index 38d8b529..00000000 --- a/examples/serialport/creaderasync/creaderasync.pro +++ /dev/null @@ -1,18 +0,0 @@ -QT = core -QT += serialport - -CONFIG += console -CONFIG -= app_bundle - -TARGET = creaderasync -TEMPLATE = app - -HEADERS += \ - serialportreader.h - -SOURCES += \ - main.cpp \ - serialportreader.cpp - -target.path = $$[QT_INSTALL_EXAMPLES]/serialport/creaderasync -INSTALLS += target diff --git a/examples/serialport/creaderasync/main.cpp b/examples/serialport/creaderasync/main.cpp deleted file mode 100644 index f371266e..00000000 --- a/examples/serialport/creaderasync/main.cpp +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (C) 2013 Laszlo Papp <lpapp@kde.org> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#include "serialportreader.h" - -#include <QCoreApplication> -#include <QSerialPort> -#include <QStringList> -#include <QTextStream> - -int main(int argc, char *argv[]) -{ - QCoreApplication coreApplication(argc, argv); - const int argumentCount = QCoreApplication::arguments().size(); - const QStringList argumentList = QCoreApplication::arguments(); - - QTextStream standardOutput(stdout); - - if (argumentCount == 1) { - standardOutput << QObject::tr("Usage: %1 <serialportname> [baudrate]") - .arg(argumentList.first()) - << Qt::endl; - return 1; - } - - QSerialPort serialPort; - const QString serialPortName = argumentList.at(1); - serialPort.setPortName(serialPortName); - - const int serialPortBaudRate = (argumentCount > 2) - ? argumentList.at(2).toInt() : QSerialPort::Baud9600; - serialPort.setBaudRate(serialPortBaudRate); - - if (!serialPort.open(QIODevice::ReadOnly)) { - standardOutput << QObject::tr("Failed to open port %1, error: %2") - .arg(serialPortName) - .arg(serialPort.errorString()) - << Qt::endl; - return 1; - } - - SerialPortReader serialPortReader(&serialPort); - - return coreApplication.exec(); -} diff --git a/examples/serialport/creaderasync/serialportreader.cpp b/examples/serialport/creaderasync/serialportreader.cpp deleted file mode 100644 index d7f399bd..00000000 --- a/examples/serialport/creaderasync/serialportreader.cpp +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (C) 2013 Laszlo Papp <lpapp@kde.org> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#include "serialportreader.h" - -#include <QCoreApplication> - -SerialPortReader::SerialPortReader(QSerialPort *serialPort, QObject *parent) : - QObject(parent), - m_serialPort(serialPort), - m_standardOutput(stdout) -{ - connect(m_serialPort, &QSerialPort::readyRead, this, &SerialPortReader::handleReadyRead); - connect(m_serialPort, &QSerialPort::errorOccurred, this, &SerialPortReader::handleError); - connect(&m_timer, &QTimer::timeout, this, &SerialPortReader::handleTimeout); - - m_timer.start(5000); -} - -void SerialPortReader::handleReadyRead() -{ - m_readData.append(m_serialPort->readAll()); - - if (!m_timer.isActive()) - m_timer.start(5000); -} - -void SerialPortReader::handleTimeout() -{ - if (m_readData.isEmpty()) { - m_standardOutput << QObject::tr("No data was currently available " - "for reading from port %1") - .arg(m_serialPort->portName()) - << Qt::endl; - } else { - m_standardOutput << QObject::tr("Data successfully received from port %1") - .arg(m_serialPort->portName()) - << Qt::endl; - m_standardOutput << m_readData << Qt::endl; - } - - QCoreApplication::quit(); -} - -void SerialPortReader::handleError(QSerialPort::SerialPortError serialPortError) -{ - if (serialPortError == QSerialPort::ReadError) { - m_standardOutput << QObject::tr("An I/O error occurred while reading " - "the data from port %1, error: %2") - .arg(m_serialPort->portName()) - .arg(m_serialPort->errorString()) - << Qt::endl; - QCoreApplication::exit(1); - } -} diff --git a/examples/serialport/creaderasync/serialportreader.h b/examples/serialport/creaderasync/serialportreader.h deleted file mode 100644 index 361db1db..00000000 --- a/examples/serialport/creaderasync/serialportreader.h +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (C) 2013 Laszlo Papp <lpapp@kde.org> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#ifndef SERIALPORTREADER_H -#define SERIALPORTREADER_H - -#include <QByteArray> -#include <QSerialPort> -#include <QTextStream> -#include <QTimer> - -QT_BEGIN_NAMESPACE - -QT_END_NAMESPACE - -class SerialPortReader : public QObject -{ - Q_OBJECT - -public: - explicit SerialPortReader(QSerialPort *serialPort, QObject *parent = nullptr); - -private slots: - void handleReadyRead(); - void handleTimeout(); - void handleError(QSerialPort::SerialPortError error); - -private: - QSerialPort *m_serialPort = nullptr; - QByteArray m_readData; - QTextStream m_standardOutput; - QTimer m_timer; -}; - -#endif // SERIALPORTREADER_H diff --git a/examples/serialport/creadersync/CMakeLists.txt b/examples/serialport/creadersync/CMakeLists.txt deleted file mode 100644 index 48714310..00000000 --- a/examples/serialport/creadersync/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(creadersync LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/serialport/creadersync") - -find_package(Qt6 REQUIRED COMPONENTS Core SerialPort) - -qt_add_executable(creadersync - main.cpp -) - -set_target_properties(creadersync PROPERTIES - WIN32_EXECUTABLE FALSE - MACOSX_BUNDLE FALSE -) - -target_link_libraries(creadersync PRIVATE - Qt::Core - Qt::SerialPort -) - -install(TARGETS creadersync - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/serialport/creadersync/creadersync.pro b/examples/serialport/creadersync/creadersync.pro deleted file mode 100644 index a2690aaf..00000000 --- a/examples/serialport/creadersync/creadersync.pro +++ /dev/null @@ -1,14 +0,0 @@ -QT = core -QT += serialport - -CONFIG += console -CONFIG -= app_bundle - -TARGET = creadersync -TEMPLATE = app - -SOURCES += \ - main.cpp - -target.path = $$[QT_INSTALL_EXAMPLES]/serialport/creadersync -INSTALLS += target diff --git a/examples/serialport/creadersync/main.cpp b/examples/serialport/creadersync/main.cpp deleted file mode 100644 index 72499eaa..00000000 --- a/examples/serialport/creadersync/main.cpp +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (C) 2013 Laszlo Papp <lpapp@kde.org> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#include <QCoreApplication> -#include <QSerialPort> -#include <QStringList> -#include <QTextStream> - -int main(int argc, char *argv[]) -{ - QCoreApplication coreApplication(argc, argv); - const int argumentCount = QCoreApplication::arguments().size(); - const QStringList argumentList = QCoreApplication::arguments(); - - QTextStream standardOutput(stdout); - - if (argumentCount == 1) { - standardOutput << QObject::tr("Usage: %1 <serialportname> [baudrate]") - .arg(argumentList.first()) << Qt::endl; - return 1; - } - - QSerialPort serialPort; - const QString serialPortName = argumentList.at(1); - serialPort.setPortName(serialPortName); - - const int serialPortBaudRate = (argumentCount > 2) - ? argumentList.at(2).toInt() : QSerialPort::Baud9600; - serialPort.setBaudRate(serialPortBaudRate); - - if (!serialPort.open(QIODevice::ReadOnly)) { - standardOutput << QObject::tr("Failed to open port %1, error: %2") - .arg(serialPortName).arg(serialPort.error()) << Qt::endl; - return 1; - } - - QByteArray readData = serialPort.readAll(); - while (serialPort.waitForReadyRead(5000)) - readData.append(serialPort.readAll()); - - if (serialPort.error() == QSerialPort::ReadError) { - standardOutput << QObject::tr("Failed to read from port %1, error: %2") - .arg(serialPortName).arg(serialPort.errorString()) << Qt::endl; - return 1; - } else if (serialPort.error() == QSerialPort::TimeoutError && readData.isEmpty()) { - standardOutput << QObject::tr("No data was currently available" - " for reading from port %1") - .arg(serialPortName) << Qt::endl; - return 0; - } - - standardOutput << QObject::tr("Data successfully received from port %1") - .arg(serialPortName) << Qt::endl; - standardOutput << readData << Qt::endl; - - return 0; -} diff --git a/examples/serialport/cwriterasync/CMakeLists.txt b/examples/serialport/cwriterasync/CMakeLists.txt deleted file mode 100644 index 7f64ccb8..00000000 --- a/examples/serialport/cwriterasync/CMakeLists.txt +++ /dev/null @@ -1,36 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(cwriterasync LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/serialport/cwriterasync") - -find_package(Qt6 REQUIRED COMPONENTS Core SerialPort) - -qt_add_executable(cwriterasync - main.cpp - serialportwriter.cpp serialportwriter.h -) - -set_target_properties(cwriterasync PROPERTIES - WIN32_EXECUTABLE FALSE - MACOSX_BUNDLE FALSE -) - -target_link_libraries(cwriterasync PRIVATE - Qt::Core - Qt::SerialPort -) - -install(TARGETS cwriterasync - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/serialport/cwriterasync/cwriterasync.pro b/examples/serialport/cwriterasync/cwriterasync.pro deleted file mode 100644 index f6105bc9..00000000 --- a/examples/serialport/cwriterasync/cwriterasync.pro +++ /dev/null @@ -1,18 +0,0 @@ -QT = core -QT += serialport - -CONFIG += console -CONFIG -= app_bundle - -TARGET = cwriterasync -TEMPLATE = app - -HEADERS += \ - serialportwriter.h - -SOURCES += \ - main.cpp \ - serialportwriter.cpp - -target.path = $$[QT_INSTALL_EXAMPLES]/serialport/cwriterasync -INSTALLS += target diff --git a/examples/serialport/cwriterasync/main.cpp b/examples/serialport/cwriterasync/main.cpp deleted file mode 100644 index 9424a264..00000000 --- a/examples/serialport/cwriterasync/main.cpp +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (C) 2013 Laszlo Papp <lpapp@kde.org> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#include "serialportwriter.h" - -#include <QCoreApplication> -#include <QFile> -#include <QSerialPort> -#include <QStringList> -#include <QTextStream> - -int main(int argc, char *argv[]) -{ - QCoreApplication coreApplication(argc, argv); - const int argumentCount = QCoreApplication::arguments().size(); - const QStringList argumentList = QCoreApplication::arguments(); - - QTextStream standardOutput(stdout); - - if (argumentCount == 1) { - standardOutput << QObject::tr("Usage: %1 <serialportname> [baudrate]") - .arg(argumentList.first()) << Qt::endl; - return 1; - } - - QSerialPort serialPort; - const QString serialPortName = argumentList.at(1); - serialPort.setPortName(serialPortName); - - const int serialPortBaudRate = (argumentCount > 2) - ? argumentList.at(2).toInt() : QSerialPort::Baud9600; - serialPort.setBaudRate(serialPortBaudRate); - - serialPort.open(QIODevice::WriteOnly); - - QFile dataFile; - if (!dataFile.open(stdin, QIODevice::ReadOnly)) { - standardOutput << QObject::tr("Failed to open stdin for reading") << Qt::endl; - return 1; - } - - const QByteArray writeData(dataFile.readAll()); - dataFile.close(); - - if (writeData.isEmpty()) { - standardOutput << QObject::tr("Either no data was currently available on " - "the standard input for reading, " - "or an error occurred for port %1, error: %2") - .arg(serialPortName).arg(serialPort.errorString()) << Qt::endl; - return 1; - } - - SerialPortWriter serialPortWriter(&serialPort); - serialPortWriter.write(writeData); - - return coreApplication.exec(); -} diff --git a/examples/serialport/cwriterasync/serialportwriter.cpp b/examples/serialport/cwriterasync/serialportwriter.cpp deleted file mode 100644 index 0331b268..00000000 --- a/examples/serialport/cwriterasync/serialportwriter.cpp +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright (C) 2013 Laszlo Papp <lpapp@kde.org> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#include "serialportwriter.h" - -#include <QCoreApplication> - -SerialPortWriter::SerialPortWriter(QSerialPort *serialPort, QObject *parent) : - QObject(parent), - m_serialPort(serialPort), - m_standardOutput(stdout) -{ - m_timer.setSingleShot(true); - connect(m_serialPort, &QSerialPort::bytesWritten, - this, &SerialPortWriter::handleBytesWritten); - connect(m_serialPort, &QSerialPort::errorOccurred, - this, &SerialPortWriter::handleError); - connect(&m_timer, &QTimer::timeout, this, &SerialPortWriter::handleTimeout); -} - -void SerialPortWriter::handleBytesWritten(qint64 bytes) -{ - m_bytesWritten += bytes; - if (m_bytesWritten == m_writeData.size()) { - m_bytesWritten = 0; - m_standardOutput << QObject::tr("Data successfully sent to port %1") - .arg(m_serialPort->portName()) << Qt::endl; - QCoreApplication::quit(); - } -} - -void SerialPortWriter::handleTimeout() -{ - m_standardOutput << QObject::tr("Operation timed out for port %1, error: %2") - .arg(m_serialPort->portName()) - .arg(m_serialPort->errorString()) - << Qt::endl; - QCoreApplication::exit(1); -} - -void SerialPortWriter::handleError(QSerialPort::SerialPortError serialPortError) -{ - if (serialPortError == QSerialPort::WriteError) { - m_standardOutput << QObject::tr("An I/O error occurred while writing" - " the data to port %1, error: %2") - .arg(m_serialPort->portName()) - .arg(m_serialPort->errorString()) - << Qt::endl; - QCoreApplication::exit(1); - } -} - -void SerialPortWriter::write(const QByteArray &writeData) -{ - m_writeData = writeData; - - const qint64 bytesWritten = m_serialPort->write(writeData); - - if (bytesWritten == -1) { - m_standardOutput << QObject::tr("Failed to write the data to port %1, error: %2") - .arg(m_serialPort->portName()) - .arg(m_serialPort->errorString()) - << Qt::endl; - QCoreApplication::exit(1); - } else if (bytesWritten != m_writeData.size()) { - m_standardOutput << QObject::tr("Failed to write all the data to port %1, error: %2") - .arg(m_serialPort->portName()) - .arg(m_serialPort->errorString()) - << Qt::endl; - QCoreApplication::exit(1); - } - - m_timer.start(5000); -} diff --git a/examples/serialport/cwriterasync/serialportwriter.h b/examples/serialport/cwriterasync/serialportwriter.h deleted file mode 100644 index 371fe2af..00000000 --- a/examples/serialport/cwriterasync/serialportwriter.h +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (C) 2013 Laszlo Papp <lpapp@kde.org> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#ifndef SERIALPORTWRITER_H -#define SERIALPORTWRITER_H - -#include <QByteArray> -#include <QObject> -#include <QSerialPort> -#include <QTextStream> -#include <QTimer> - -QT_BEGIN_NAMESPACE - -QT_END_NAMESPACE - -class SerialPortWriter : public QObject -{ - Q_OBJECT - -public: - explicit SerialPortWriter(QSerialPort *serialPort, QObject *parent = nullptr); - void write(const QByteArray &writeData); - -private slots: - void handleBytesWritten(qint64 bytes); - void handleTimeout(); - void handleError(QSerialPort::SerialPortError error); - -private: - QSerialPort *m_serialPort = nullptr; - QByteArray m_writeData; - QTextStream m_standardOutput; - qint64 m_bytesWritten = 0; - QTimer m_timer; -}; - -#endif // SERIALPORTWRITER_H diff --git a/examples/serialport/cwritersync/CMakeLists.txt b/examples/serialport/cwritersync/CMakeLists.txt deleted file mode 100644 index 7c1850c0..00000000 --- a/examples/serialport/cwritersync/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(cwritersync LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/serialport/cwritersync") - -find_package(Qt6 REQUIRED COMPONENTS Core SerialPort) - -qt_add_executable(cwritersync - main.cpp -) - -set_target_properties(cwritersync PROPERTIES - WIN32_EXECUTABLE FALSE - MACOSX_BUNDLE FALSE -) - -target_link_libraries(cwritersync PRIVATE - Qt::Core - Qt::SerialPort -) - -install(TARGETS cwritersync - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/serialport/cwritersync/cwritersync.pro b/examples/serialport/cwritersync/cwritersync.pro deleted file mode 100644 index 1e0996dc..00000000 --- a/examples/serialport/cwritersync/cwritersync.pro +++ /dev/null @@ -1,14 +0,0 @@ -QT = core -QT += serialport - -CONFIG += console -CONFIG -= app_bundle - -TARGET = cwritersync -TEMPLATE = app - -SOURCES += \ - main.cpp - -target.path = $$[QT_INSTALL_EXAMPLES]/serialport/cwritersync -INSTALLS += target diff --git a/examples/serialport/cwritersync/main.cpp b/examples/serialport/cwritersync/main.cpp deleted file mode 100644 index 0eb9a90a..00000000 --- a/examples/serialport/cwritersync/main.cpp +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright (C) 2013 Laszlo Papp <lpapp@kde.org> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#include <QCoreApplication> -#include <QFile> -#include <QSerialPort> -#include <QStringList> -#include <QTextStream> - -int main(int argc, char *argv[]) -{ - QCoreApplication coreApplication(argc, argv); - const int argumentCount = QCoreApplication::arguments().size(); - const QStringList argumentList = QCoreApplication::arguments(); - - QTextStream standardOutput(stdout); - - if (argumentCount == 1) { - standardOutput << QObject::tr("Usage: %1 <serialportname> [baudrate]") - .arg(argumentList.first()) << Qt::endl; - return 1; - } - - QSerialPort serialPort; - const QString serialPortName = argumentList.at(1); - serialPort.setPortName(serialPortName); - - const int serialPortBaudRate = (argumentCount > 2) - ? argumentList.at(2).toInt() : QSerialPort::Baud9600; - serialPort.setBaudRate(serialPortBaudRate); - - if (!serialPort.open(QIODevice::WriteOnly)) { - standardOutput << QObject::tr("Failed to open port %1, error: %2") - .arg(serialPortName).arg(serialPort.errorString()) - << Qt::endl; - return 1; - } - - QFile dataFile; - if (!dataFile.open(stdin, QIODevice::ReadOnly)) { - standardOutput << QObject::tr("Failed to open stdin for reading") - << Qt::endl; - return 1; - } - - QByteArray writeData(dataFile.readAll()); - dataFile.close(); - - if (writeData.isEmpty()) { - standardOutput << QObject::tr("Either no data was currently available on " - "the standard input for reading, or an error " - "occurred for port %1, error: %2") - .arg(serialPortName).arg(serialPort.errorString()) << Qt::endl; - return 1; - } - - const qint64 bytesWritten = serialPort.write(writeData); - - if (bytesWritten == -1) { - standardOutput << QObject::tr("Failed to write the data to port %1, error: %2") - .arg(serialPortName).arg(serialPort.errorString()) << Qt::endl; - return 1; - } else if (bytesWritten != writeData.size()) { - standardOutput << QObject::tr("Failed to write all the data to port %1, error: %2") - .arg(serialPortName).arg(serialPort.errorString()) << Qt::endl; - return 1; - } else if (!serialPort.waitForBytesWritten(5000)) { - standardOutput << QObject::tr("Operation timed out or an error " - "occurred for port %1, error: %2") - .arg(serialPortName).arg(serialPort.errorString()) << Qt::endl; - return 1; - } - - standardOutput << QObject::tr("Data successfully sent to port %1") - .arg(serialPortName) << Qt::endl; - - return 0; -} diff --git a/examples/serialport/doc/blockingreceiver.qdoc b/examples/serialport/doc/blockingreceiver.qdoc index a94f7a26..71a2084d 100644 --- a/examples/serialport/doc/blockingreceiver.qdoc +++ b/examples/serialport/doc/blockingreceiver.qdoc @@ -4,8 +4,10 @@ /*! \example blockingreceiver - \title Blocking Receiver Example + \title Blocking Receiver \ingroup qtserialport-examples + \examplecategory Connectivity + \brief Shows how to use the synchronous API of QSerialPort in a non-GUI thread. \e{Blocking Receiver} shows how to create an application for a serial interface @@ -42,8 +44,8 @@ But contrary to what many think, using threads with QThread does not necessarily add unmanageable complexity to your application. - This application is a Receiver, that demonstrate the work paired with Sender - application \l{Blocking Sender Example}. + This application is a Receiver, that demonstrate the work paired with the + sender application \l{blockingsender}{Blocking Sender example}. The Receiver application receives the request via serial port from the Sender application and send a response to it. @@ -137,7 +139,7 @@ \snippet blockingreceiver/receiverthread.cpp 13 - \sa {Terminal Example}, {Blocking Sender Example} + \sa {Serial Terminal}, {Blocking Sender} \include examples-run.qdocinc */ diff --git a/examples/serialport/doc/blockingsender.qdoc b/examples/serialport/doc/blockingsender.qdoc index 2702e184..db28b725 100644 --- a/examples/serialport/doc/blockingsender.qdoc +++ b/examples/serialport/doc/blockingsender.qdoc @@ -1,12 +1,14 @@ // Copyright (C) 2011 - 2012 Denis Shienkov <denis.shienkov@gmail.com> // Copyright (C) 2012 - 2013 Laszlo Papp <lpapp@kde.org> -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only /*! \example blockingsender - \title Blocking Sender Example + \title Blocking Sender \ingroup qtserialport-examples + \examplecategory Connectivity + \brief Shows how to use the synchronous API of QSerialPort in a worker thread. \e{Blocking Sender} shows how to create an application for a serial @@ -41,8 +43,8 @@ should only be used in non-GUI threads to keep the user interface responsive. - This application is the sender which demonstrates the work paired with the receiver - application \l{blockingreceiver}{Blocking Receiver Example}. + This application is the sender which demonstrates the work paired with the + receiver application \l{blockingreceiver}{Blocking Receiver example}. The sender application initiates the transfer request via the serial port to the receiver application and waits for response. @@ -137,7 +139,7 @@ \snippet blockingsender/senderthread.cpp 13 - \sa {Terminal Example}, {Blocking Receiver Example} + \sa {Serial Terminal}, {Blocking Receiver} \include examples-run.qdocinc */ diff --git a/examples/serialport/doc/cenumerator.qdoc b/examples/serialport/doc/cenumerator.qdoc deleted file mode 100644 index f07a79a6..00000000 --- a/examples/serialport/doc/cenumerator.qdoc +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (C) 2012 Laszlo Papp <lpapp@kde.org> -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only - -/*! - \example cenumerator - \title Command Line Enumerator Example - \ingroup qtserialport-examples - \brief Shows how to get information about serial devices in a system. - - \e{Command Line Enumerator} shows how to use the class QSerialPortInfo for - getting information about serial devices that are present in the system. - - \image cenumerator-example.png - - This command line example displays information about serial ports in a - console, provided by the class QSerialPortInfo. - - For getting information about the available ports, use the static method - \l{QSerialPortInfo::availablePorts()}{availablePorts()}. - - \include examples-run.qdocinc -*/ diff --git a/examples/serialport/doc/creaderasync.qdoc b/examples/serialport/doc/creaderasync.qdoc deleted file mode 100644 index 7843754a..00000000 --- a/examples/serialport/doc/creaderasync.qdoc +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (C) 2013 Laszlo Papp <lpapp@kde.org> -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only - -/*! - \example creaderasync - \title Command Line Reader Async Example - \ingroup qtserialport-examples - \brief Shows how to receive data asynchronously over serial port. - - \e{Command Line Reader Async} shows how to use the QSerialPort class for - receiving data asynchronously over the selected serial port with the desired - settings. - - \image creaderasync-example.png - - This command line reader async example receives data asynchronously over the - selected serial port in a console, provided by the QSerialPort class. - - For receiving data synchronously over the selected serial port, use the - \l{QSerialPort::read()}{read()} or \l{QSerialPort::readAll()}{readAll()} - methods, and \l{QIODevice::readyRead()}{readyRead()} signal. - - \include examples-run.qdocinc -*/ diff --git a/examples/serialport/doc/creadersync.qdoc b/examples/serialport/doc/creadersync.qdoc deleted file mode 100644 index f2f3fd8e..00000000 --- a/examples/serialport/doc/creadersync.qdoc +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (C) 2013 Laszlo Papp <lpapp@kde.org> -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only - -/*! - \example creadersync - \title Command Line Reader Sync Example - \ingroup qtserialport-examples - \brief Shows how to receive data synchronously over serial port. - - \e{Command Line Reader Sync} shows how to use the QSerialPort class - for receiving data synchronously over the selected serial port with the - desired settings. - - \image creadersync-example.png - - This command line reader sync example receives data synchronously over the - selected serial port in a console, provided by the QSerialPort class. - - For receiving data synchronously over the selected serial port, use the - \l{QSerialPort::read()}{read()} or \l{QSerialPort::readAll()}{readAll()}, - and \l{QIODevice::waitForReadyRead()}{waitForReadyRead()} methods. - - \include examples-run.qdocinc -*/ diff --git a/examples/serialport/doc/cwriterasync.qdoc b/examples/serialport/doc/cwriterasync.qdoc deleted file mode 100644 index bce1de00..00000000 --- a/examples/serialport/doc/cwriterasync.qdoc +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (C) 2013 Laszlo Papp <lpapp@kde.org> -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only - -/*! - \example cwriterasync - \title Command Line Writer Async Example - \ingroup qtserialport-examples - \brief Shows how to send data asynchronously over serial port. - - \e{Command Line Writer Async} shows how to use the QSerialPort class for - sending data asynchronously over the selected serial port with the desired - settings. - - \image cwriterasync-example.png - - This command line writer async example sends data asynchronously over the - selected serial port in a console, provided by the QSerialPort class. - - For sending data asynchronously over the selected serial port, use the - \l{QIODevice::write()}{write()} method and - \l{QIODevice::bytesWritten()}{bytesWritten()} signal. - - \include examples-run.qdocinc -*/ diff --git a/examples/serialport/doc/cwritersync.qdoc b/examples/serialport/doc/cwritersync.qdoc deleted file mode 100644 index 1cbb5a65..00000000 --- a/examples/serialport/doc/cwritersync.qdoc +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (C) 2013 Laszlo Papp <lpapp@kde.org> -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only - -/*! - \example cwritersync - \title Command Line Writer Sync Example - \ingroup qtserialport-examples - \brief Shows how to send data synchronously over serial port. - - \e{Command Line Writer Sync} shows how to use the QSerialPort class for - sending data synchronously over the selected serial port with the desired - settings. - - \image cwritersync-example.png - - This command line writer sync example sends data synchronously over the - selected serial port in a console, provided by the QSerialPort class. - - For sending data synchronously over the selected serial port, use the - \l{QIODevice::write()}{write()} and - \l{QIODevice::waitForBytesWritten()}{waitForBytesWritten()} methods. - - \include examples-run.qdocinc -*/ diff --git a/examples/serialport/doc/enumerator.qdoc b/examples/serialport/doc/enumerator.qdoc deleted file mode 100644 index cdb494ed..00000000 --- a/examples/serialport/doc/enumerator.qdoc +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (C) 2011 - 2012 Denis Shienkov <denis.shienkov@gmail.com> -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only - -/*! - \example enumerator - \title Enumerator Example - \ingroup qtserialport-examples - \brief Shows how to display information about serial devices in a system. - - \e Enumerator shows how to use the class QSerialPortInfo for - getting information about serial devices that are present in the system. - - \image enumerator-example.png - - This GUI example displays information about serial ports in a widget, - provided by the class QSerialPortInfo. - - For getting information about the available ports, use the static method - \l{QSerialPortInfo::availablePorts()}{availablePorts()}. - - \include examples-run.qdocinc -*/ diff --git a/examples/serialport/doc/terminal.qdoc b/examples/serialport/doc/terminal.qdoc index c693954a..c90a3c0b 100644 --- a/examples/serialport/doc/terminal.qdoc +++ b/examples/serialport/doc/terminal.qdoc @@ -1,11 +1,13 @@ // Copyright (C) 2011 - 2012 Denis Shienkov <denis.shienkov@gmail.com> -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only /*! \example terminal - \title Terminal Example + \title Serial Terminal \ingroup qtserialport-examples + \examplecategory Connectivity + \brief Shows how to use various features of QSerialPort. \e Terminal shows how to create a terminal for a simple serial interface by @@ -63,12 +65,16 @@ happens automatically according to the parent and child mechanism in Qt: \snippet terminal/mainwindow.cpp 0 - \dots \snippet terminal/mainwindow.cpp 1 + \dots - The only QSerialPort signal invoked in this example is - \l{QIODevice::}{readyRead()}, which shows that new data has been - received and hence available: + This example demonstrates the following \l QSerialPort signals: + \list + \li \l {QIODevice::}{readyRead()} - shows that new data has been + received and hence available + \li \l {QIODevice::}{bytesWritten()} - used to check that all data was + written successfully + \endlist \dots \snippet terminal/mainwindow.cpp 2 @@ -79,7 +85,8 @@ \snippet terminal/mainwindow.cpp 4 - In this slot, the settings are read from \c{SettingsDialog} and an attempt is made to open and initialize the serial + In this slot, the settings are read from \c{SettingsDialog} and an attempt + is made to open and initialize the serial port accordingly. If successful, the status bar displays a message that the opening was successful with the given configuration; otherwise, a messagebox is displayed with the appropriate error code and message. If the serial port @@ -93,12 +100,30 @@ In this case, handled by the closure of the serial port. + Clicking on the \b{Configure} button invokes the \c{show()} slot which + belongs to the \c{SettingsDialog} widget. + + This method (\c{terminal/settingsdialog.cpp}) displays the \c{SettingsDialog}, + in which the user can choose the desired serial port, see the information + about the selected port, and set the desired parameters of the given serial + port. + + \section2 Writing Data + Typing characters in the console invokes the \c writeData() slot: \snippet terminal/mainwindow.cpp 6 This slot sends the characters typed in the given Console widget to the serial port - see \c terminal/console.cpp. + It also starts a timer to track if the write actually succeeded or not. + We use the \l {QIODevice::}{bytesWritten()} signal to make sure that all + bytes are actually written. It is connected to the + \c {MainWindow::handleBytesWritten()} slot: + + \snippet terminal/mainwindow.cpp 9 + + \section2 Reading Data When the serial port receives new data, the signal \l{QIODevice::}{readyRead()} is emitted, and that signal is @@ -109,15 +134,7 @@ This slot reads the data from the serial port and displays that in the Console widget. - Clicking on the \b{Configure} button invokes the \c{show()} slot which - belongs to the \c{SettingsDialog} widget. - - This method (\c{terminal/settingsdialog.cpp}) displays the \c{SettingsDialog}, - in which the user can choose the desired serial port, see the information - about the selected port, and set the desired parameters of the given serial - port. - - \sa {Blocking Receiver Example} + \sa {Blocking Receiver} \include examples-run.qdocinc */ diff --git a/examples/serialport/enumerator/CMakeLists.txt b/examples/serialport/enumerator/CMakeLists.txt deleted file mode 100644 index ca88ab24..00000000 --- a/examples/serialport/enumerator/CMakeLists.txt +++ /dev/null @@ -1,37 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(enumerator LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/serialport/enumerator") - -find_package(Qt6 REQUIRED COMPONENTS Core Gui SerialPort Widgets) - -qt_add_executable(enumerator - main.cpp -) - -set_target_properties(enumerator PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(enumerator PRIVATE - Qt::Core - Qt::Gui - Qt::SerialPort - Qt::Widgets -) - -install(TARGETS enumerator - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/serialport/enumerator/enumerator.pro b/examples/serialport/enumerator/enumerator.pro deleted file mode 100644 index 3989335a..00000000 --- a/examples/serialport/enumerator/enumerator.pro +++ /dev/null @@ -1,10 +0,0 @@ -QT += widgets serialport - -TARGET = enumerator -TEMPLATE = app - -SOURCES += \ - main.cpp - -target.path = $$[QT_INSTALL_EXAMPLES]/serialport/enumerator -INSTALLS += target diff --git a/examples/serialport/enumerator/main.cpp b/examples/serialport/enumerator/main.cpp deleted file mode 100644 index 78cadc5a..00000000 --- a/examples/serialport/enumerator/main.cpp +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (C) 2012 Denis Shienkov <denis.shienkov@gmail.com> -// Copyright (C) 2012 Laszlo Papp <lpapp@kde.org> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#include <QApplication> -#include <QLabel> -#include <QScrollArea> -#include <QSerialPortInfo> -#include <QVBoxLayout> -#include <QWidget> - -int main(int argc, char *argv[]) -{ - QApplication a(argc, argv); - - auto layout = new QVBoxLayout; - - const auto infos = QSerialPortInfo::availablePorts(); - for (const QSerialPortInfo &info : infos) { - QString s = QObject::tr("Port: ") + info.portName() + "\n" - + QObject::tr("Location: ") + info.systemLocation() + "\n" - + QObject::tr("Description: ") + info.description() + "\n" - + QObject::tr("Manufacturer: ") + info.manufacturer() + "\n" - + QObject::tr("Serial number: ") + info.serialNumber() + "\n" - + QObject::tr("Vendor Identifier: ") + (info.hasVendorIdentifier() ? QString::number(info.vendorIdentifier(), 16) : QString()) + "\n" - + QObject::tr("Product Identifier: ") + (info.hasProductIdentifier() ? QString::number(info.productIdentifier(), 16) : QString()) + "\n"; - - auto label = new QLabel(s); - layout->addWidget(label); - } - - auto workPage = new QWidget; - workPage->setLayout(layout); - - QScrollArea area; - area.setWindowTitle(QObject::tr("Info about all available serial ports.")); - area.setWidget(workPage); - area.show(); - - return a.exec(); -} diff --git a/examples/serialport/serialport.pro b/examples/serialport/serialport.pro index d04911a7..7a70fbbc 100644 --- a/examples/serialport/serialport.pro +++ b/examples/serialport/serialport.pro @@ -1,3 +1,2 @@ TEMPLATE = subdirs -SUBDIRS = cenumerator creaderasync creadersync cwriterasync cwritersync -!isEmpty(QT.widgets.name):SUBDIRS += enumerator terminal blockingsender blockingreceiver sender receiver +!isEmpty(QT.widgets.name):SUBDIRS += terminal blockingsender blockingreceiver diff --git a/examples/serialport/terminal/CMakeLists.txt b/examples/serialport/terminal/CMakeLists.txt index 4a5a3d47..d38e209f 100644 --- a/examples/serialport/terminal/CMakeLists.txt +++ b/examples/serialport/terminal/CMakeLists.txt @@ -1,12 +1,9 @@ # Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause cmake_minimum_required(VERSION 3.16) project(terminal LANGUAGES CXX) -set(CMAKE_AUTOMOC ON) -set(CMAKE_AUTOUIC ON) - if(NOT DEFINED INSTALL_EXAMPLESDIR) set(INSTALL_EXAMPLESDIR "examples") endif() @@ -15,6 +12,8 @@ set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/serialport/terminal") find_package(Qt6 REQUIRED COMPONENTS Core Gui SerialPort Widgets) +qt_standard_project_setup() + qt_add_executable(terminal console.cpp console.h main.cpp @@ -43,7 +42,7 @@ set(terminal_resource_files "images/settings.png" ) -qt6_add_resources(terminal "terminal" +qt_add_resources(terminal "terminal" PREFIX "/" FILES diff --git a/examples/serialport/terminal/mainwindow.cpp b/examples/serialport/terminal/mainwindow.cpp index 56cf998d..d8c02122 100644 --- a/examples/serialport/terminal/mainwindow.cpp +++ b/examples/serialport/terminal/mainwindow.cpp @@ -9,19 +9,25 @@ #include <QLabel> #include <QMessageBox> +#include <QTimer> + +#include <chrono> + +static constexpr std::chrono::seconds kWriteTimeout = std::chrono::seconds{5}; //! [0] MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), m_ui(new Ui::MainWindow), +//! [0] m_status(new QLabel), m_console(new Console), - m_settings(new SettingsDialog(this)), + m_settings(new SettingsDialog(this)), + m_timer(new QTimer(this)), //! [1] m_serial(new QSerialPort(this)) -//! [1] { -//! [0] +//! [1] m_ui->setupUi(this); m_console->setEnabled(false); setCentralWidget(m_console); @@ -36,9 +42,12 @@ MainWindow::MainWindow(QWidget *parent) : initActionsConnections(); connect(m_serial, &QSerialPort::errorOccurred, this, &MainWindow::handleError); + connect(m_timer, &QTimer::timeout, this, &MainWindow::handleWriteTimeout); + m_timer->setSingleShot(true); //! [2] connect(m_serial, &QSerialPort::readyRead, this, &MainWindow::readData); + connect(m_serial, &QSerialPort::bytesWritten, this, &MainWindow::handleBytesWritten); //! [2] connect(m_console, &Console::getData, this, &MainWindow::writeData); //! [3] @@ -93,8 +102,8 @@ void MainWindow::closeSerialPort() void MainWindow::about() { - QMessageBox::about(this, tr("About Simple Terminal"), - tr("The <b>Simple Terminal</b> example demonstrates how to " + QMessageBox::about(this, tr("About Serial Terminal"), + tr("The <b>Serial Terminal</b> example demonstrates how to " "use the Qt Serial Port module in modern GUI applications " "using Qt, with a menu bar, toolbars, and a status bar.")); } @@ -102,7 +111,16 @@ void MainWindow::about() //! [6] void MainWindow::writeData(const QByteArray &data) { - m_serial->write(data); + const qint64 written = m_serial->write(data); + if (written == data.size()) { + m_bytesToWrite += written; + m_timer->start(kWriteTimeout); + } else { + const QString error = tr("Failed to write all data to port %1.\n" + "Error: %2").arg(m_serial->portName(), + m_serial->errorString()); + showWriteError(error); + } } //! [6] @@ -124,6 +142,23 @@ void MainWindow::handleError(QSerialPort::SerialPortError error) } //! [8] +//! [9] +void MainWindow::handleBytesWritten(qint64 bytes) +{ + m_bytesToWrite -= bytes; + if (m_bytesToWrite == 0) + m_timer->stop(); +} +//! [9] + +void MainWindow::handleWriteTimeout() +{ + const QString error = tr("Write operation timed out for port %1.\n" + "Error: %2").arg(m_serial->portName(), + m_serial->errorString()); + showWriteError(error); +} + void MainWindow::initActionsConnections() { connect(m_ui->actionConnect, &QAction::triggered, this, &MainWindow::openSerialPort); @@ -139,3 +174,8 @@ void MainWindow::showStatusMessage(const QString &message) { m_status->setText(message); } + +void MainWindow::showWriteError(const QString &message) +{ + QMessageBox::warning(this, tr("Warning"), message); +} diff --git a/examples/serialport/terminal/mainwindow.h b/examples/serialport/terminal/mainwindow.h index a0fcb62a..975f9a40 100644 --- a/examples/serialport/terminal/mainwindow.h +++ b/examples/serialport/terminal/mainwindow.h @@ -11,6 +11,7 @@ QT_BEGIN_NAMESPACE class QLabel; +class QTimer; namespace Ui { class MainWindow; @@ -37,17 +38,22 @@ private slots: void readData(); void handleError(QSerialPort::SerialPortError error); + void handleBytesWritten(qint64 bytes); + void handleWriteTimeout(); private: void initActionsConnections(); private: void showStatusMessage(const QString &message); + void showWriteError(const QString &message); Ui::MainWindow *m_ui = nullptr; QLabel *m_status = nullptr; Console *m_console = nullptr; SettingsDialog *m_settings = nullptr; + qint64 m_bytesToWrite = 0; + QTimer *m_timer = nullptr; QSerialPort *m_serial = nullptr; }; diff --git a/examples/serialport/terminal/mainwindow.ui b/examples/serialport/terminal/mainwindow.ui index 452fdd53..be0861f3 100644 --- a/examples/serialport/terminal/mainwindow.ui +++ b/examples/serialport/terminal/mainwindow.ui @@ -11,7 +11,7 @@ </rect> </property> <property name="windowTitle"> - <string>Simple Terminal</string> + <string>Serial Terminal</string> </property> <widget class="QWidget" name="centralWidget"> <layout class="QVBoxLayout" name="verticalLayout"/> diff --git a/licenseRule.json b/licenseRule.json new file mode 100644 index 00000000..36f81257 --- /dev/null +++ b/licenseRule.json @@ -0,0 +1,84 @@ +[ + { + "comment" : ["file_pattern_ending: strings matched against the end of a file name.", + "location keys: regular expression matched against the beginning of", + "the file path (relative to the git submodule root).", + "spdx: list of SPDX-License-Expression's allowed in the matching files.", + "-------------------------------------------------------", + "Files with the following endings are Build System licensed,", + "unless they are examples", + "Files with other endings can also be build system files" + ], + "file_pattern_ending" : ["CMakeLists.txt", ".cmake", ".pro", ".pri", ".prf", + "configure", "configure.bat", "cmake.in", "plist.in", "CMakeLists.txt.in"], + "location" : { + "" : { + "comment" : "Default", + "file type" : "build system", + "spdx" : ["BSD-3-Clause"] + }, + "(.*)(examples/|snippets/)" : { + "comment" : "Example takes precedence", + "file type" : "examples and snippets", + "spdx" : ["LicenseRef-Qt-Commercial OR BSD-3-Clause"] + } + } + }, + { + "comments" : ["Files with the following endings are Tool licensed,", + "unless they are examples.", + "Files with other endings can also be tool files."], + "file_pattern_ending" : [".sh", ".py", ".pl", ".bat", ".ps1"], + "location" :{ + "" : { + "comment" : "Default", + "file type" : "tools and utils", + "spdx" : ["LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0"] + }, + "(.*)(examples/|snippets/)" : { + "comment" : "Example takes precedence", + "file type" : "examples and snippets", + "spdx" : ["LicenseRef-Qt-Commercial OR BSD-3-Clause"] + } + } + }, + { + "comment" : "Files with the following endings are Documentation licensed.", + "file_pattern_ending" : [".qdoc", ".qdocinc" , ".qdocconf", ".txt", "README", "qt_attribution.json"], + "location" :{ + "" : { + "comment" : "", + "file type" : "documentation", + "spdx" : ["LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only"] + } + } + }, + { + "comment" : ["All other files", + "The licensing is defined only by the file location in the Qt module repository.", + "NO <file_pattern_ending> key for this case!", + "This needs to be the last entry of the file."], + "location" : { + "" : { + "comment" : "Default", + "file type" : "module and plugin", + "spdx" : ["LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only"] + }, + "src/" : { + "comment" : "Default", + "file type" : "module and plugin", + "spdx" : ["LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only"] + }, + "tests/" : { + "comment" : "Default", + "file type" : "test", + "spdx" : ["LicenseRef-Qt-Commercial OR GPL-3.0-only"] + }, + "(.*)(examples/|snippets/)" : { + "comment" : "Default", + "file type" : "examples and snippets", + "spdx" : ["LicenseRef-Qt-Commercial OR BSD-3-Clause"] + } + } + } +] diff --git a/src/serialport/CMakeLists.txt b/src/serialport/CMakeLists.txt index b7957f3f..496d741f 100644 --- a/src/serialport/CMakeLists.txt +++ b/src/serialport/CMakeLists.txt @@ -11,6 +11,9 @@ qt_internal_add_module(SerialPort qserialport.cpp qserialport.h qserialport_p.h qserialportglobal.h qserialportinfo.cpp qserialportinfo.h qserialportinfo_p.h + removed_api.cpp + NO_PCH_SOURCES + removed_api.cpp INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR} LIBRARIES diff --git a/src/serialport/doc/images/blockingreceiver-example.png b/src/serialport/doc/images/blockingreceiver-example.png Binary files differindex c02ae859..7bdafde6 100644 --- a/src/serialport/doc/images/blockingreceiver-example.png +++ b/src/serialport/doc/images/blockingreceiver-example.png diff --git a/src/serialport/doc/images/blockingsender-example.png b/src/serialport/doc/images/blockingsender-example.png Binary files differindex 9b5fc4a6..14ee55c5 100644 --- a/src/serialport/doc/images/blockingsender-example.png +++ b/src/serialport/doc/images/blockingsender-example.png diff --git a/src/serialport/doc/images/cenumerator-example.png b/src/serialport/doc/images/cenumerator-example.png Binary files differdeleted file mode 100644 index 03792e71..00000000 --- a/src/serialport/doc/images/cenumerator-example.png +++ /dev/null diff --git a/src/serialport/doc/images/creaderasync-example.png b/src/serialport/doc/images/creaderasync-example.png Binary files differdeleted file mode 100644 index ffa3636a..00000000 --- a/src/serialport/doc/images/creaderasync-example.png +++ /dev/null diff --git a/src/serialport/doc/images/creadersync-example.png b/src/serialport/doc/images/creadersync-example.png Binary files differdeleted file mode 100644 index 476dcbe4..00000000 --- a/src/serialport/doc/images/creadersync-example.png +++ /dev/null diff --git a/src/serialport/doc/images/cwriterasync-example.png b/src/serialport/doc/images/cwriterasync-example.png Binary files differdeleted file mode 100644 index ebe11dc8..00000000 --- a/src/serialport/doc/images/cwriterasync-example.png +++ /dev/null diff --git a/src/serialport/doc/images/cwritersync-example.png b/src/serialport/doc/images/cwritersync-example.png Binary files differdeleted file mode 100644 index 669985d2..00000000 --- a/src/serialport/doc/images/cwritersync-example.png +++ /dev/null diff --git a/src/serialport/doc/images/enumerator-example.png b/src/serialport/doc/images/enumerator-example.png Binary files differdeleted file mode 100644 index c96d990c..00000000 --- a/src/serialport/doc/images/enumerator-example.png +++ /dev/null diff --git a/src/serialport/doc/images/terminal-example.png b/src/serialport/doc/images/terminal-example.png Binary files differindex 9affaae1..7cdbd213 100644 --- a/src/serialport/doc/images/terminal-example.png +++ b/src/serialport/doc/images/terminal-example.png diff --git a/src/serialport/doc/qtserialport.qdocconf b/src/serialport/doc/qtserialport.qdocconf index 270449fb..a852fb3d 100644 --- a/src/serialport/doc/qtserialport.qdocconf +++ b/src/serialport/doc/qtserialport.qdocconf @@ -27,12 +27,16 @@ qhp.QtSerialPort.subprojects.examples.sortPages = true headerdirs += .. sourcedirs += .. -exampledirs += ../../../examples/serialport +exampledirs += \ + ../../../examples/serialport \ + snippets + +excludedirs += snippets imagedirs += images examplesinstallpath = serialport -depends += qtcore qtdoc qtnetwork qmake +depends += qtcore qtdoc qtnetwork qmake qtcmake navigation.landingpage = "Qt Serial Port" navigation.cppclassespage = "Qt Serial Port C++ Classes" diff --git a/src/serialport/doc/snippets/doc_src_serialport.cpp b/src/serialport/doc/snippets/doc_src_serialport.cpp new file mode 100644 index 00000000..11476c91 --- /dev/null +++ b/src/serialport/doc/snippets/doc_src_serialport.cpp @@ -0,0 +1,41 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +#include <QtCore/qcoreapplication.h> +#include <QtCore/qdebug.h> + +#include <QtSerialPort/qserialportinfo.h> + +void enumeratePorts() +{ +//! [enumerate_ports] + const auto serialPortInfos = QSerialPortInfo::availablePorts(); + for (const QSerialPortInfo &portInfo : serialPortInfos) { + qDebug() << "\n" + << "Port:" << portInfo.portName() << "\n" + << "Location:" << portInfo.systemLocation() << "\n" + << "Description:" << portInfo.description() << "\n" + << "Manufacturer:" << portInfo.manufacturer() << "\n" + << "Serial number:" << portInfo.serialNumber() << "\n" + << "Vendor Identifier:" + << (portInfo.hasVendorIdentifier() + ? QByteArray::number(portInfo.vendorIdentifier(), 16) + : QByteArray()) << "\n" + << "Product Identifier:" + << (portInfo.hasProductIdentifier() + ? QByteArray::number(portInfo.productIdentifier(), 16) + : QByteArray()); + } +//! [enumerate_ports] +} + +int main(int argc, char **argv) +{ + QCoreApplication app(argc, argv); + + enumeratePorts(); + + return app.exec(); +} + +#include "doc_src_serialport.moc" diff --git a/src/serialport/doc/src/index.qdoc b/src/serialport/doc/src/index.qdoc index bc9ff809..3da928c2 100644 --- a/src/serialport/doc/src/index.qdoc +++ b/src/serialport/doc/src/index.qdoc @@ -7,39 +7,29 @@ \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 \li Terminal features, such as echo, control CR/LF, and so on. - \li Text mode. - \li Configuring timeouts and delays while reading or writing. - \li Pinout signal change notification. + \li Text mode display for data transfer. + \li Timeout and delay configuration while reading or writing. + \li Notification on changing pinout signal. \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 5eece08e..fadd98eb 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); - - const auto currentDataBits = d->dataBits.value(); + d->dataBits.removeBindingUnlessInWrapper(); + const auto currentDataBits = d->dataBits.valueBypassingBindings(); 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); - - const auto currentParity = d->parity.value(); + d->parity.removeBindingUnlessInWrapper(); + const auto currentParity = d->parity.valueBypassingBindings(); 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); - - const auto currentStopBits = d->stopBits.value(); + d->stopBits.removeBindingUnlessInWrapper(); + const auto currentStopBits = d->stopBits.valueBypassingBindings(); 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; } @@ -690,7 +691,7 @@ QSerialPort::StopBits QSerialPort::stopBits() const return d->stopBits; } -QBindable<bool> QSerialPort::bindableStopBits() +QBindable<QSerialPort::StopBits> QSerialPort::bindableStopBits(QT6_IMPL_NEW_OVERLOAD) { return &d_func()->stopBits; } @@ -721,16 +722,16 @@ QBindable<bool> QSerialPort::bindableStopBits() bool QSerialPort::setFlowControl(FlowControl flowControl) { Q_D(QSerialPort); - - const auto currentFlowControl = d->flowControl.value(); + d->flowControl.removeBindingUnlessInWrapper(); + const auto currentFlowControl = d->flowControl.valueBypassingBindings(); 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); - - const auto currentSet = d->isBreakEnabled.value(); + d->isBreakEnabled.removeBindingUnlessInWrapper(); + const auto currentSet = d->isBreakEnabled.valueBypassingBindings(); 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/qserialport.h b/src/serialport/qserialport.h index 3352fdbb..336ead03 100644 --- a/src/serialport/qserialport.h +++ b/src/serialport/qserialport.h @@ -6,6 +6,7 @@ #define QSERIALPORT_H #include <QtCore/qiodevice.h> +#include <QtCore/qproperty.h> #include <QtSerialPort/qserialportglobal.h> @@ -148,7 +149,10 @@ public: bool setStopBits(StopBits stopBits); StopBits stopBits() const; +#if QT_SERIALPORT_REMOVED_SINCE(6, 7) QBindable<bool> bindableStopBits(); +#endif + QBindable<StopBits> bindableStopBits(QT6_DECL_NEW_OVERLOAD); bool setFlowControl(FlowControl flowControl); FlowControl flowControl() const; diff --git a/src/serialport/qserialport_unix.cpp b/src/serialport/qserialport_unix.cpp index e0f2e79f..7e642e57 100644 --- a/src/serialport/qserialport_unix.cpp +++ b/src/serialport/qserialport_unix.cpp @@ -6,6 +6,7 @@ #include "qserialport_p.h" #include "qserialportinfo_p.h" +#include <QtCore/qdeadlinetimer.h> #include <QtCore/qelapsedtimer.h> #include <QtCore/qmap.h> #include <QtCore/qsocketnotifier.h> @@ -19,7 +20,7 @@ #include <sys/time.h> #include <unistd.h> -#ifdef Q_OS_OSX +#ifdef Q_OS_MACOS #if defined(MAC_OS_X_VERSION_10_4) && (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4) #include <IOKit/serial/ioss.h> #endif @@ -614,7 +615,7 @@ bool QSerialPortPrivate::setCustomBaudRate(qint32 baudRate, QSerialPort::Directi return setStandardBaudRate(B38400, directions); } -#elif defined(Q_OS_OSX) +#elif defined(Q_OS_MACOS) bool QSerialPortPrivate::setCustomBaudRate(qint32 baudRate, QSerialPort::Directions directions) { @@ -750,7 +751,7 @@ bool QSerialPortPrivate::readNotification() buffer.chop(bytesToRead - qMax(readBytes, qint64(0))); - if (readBytes <= 0) { + if (readBytes < 0) { QSerialPortErrorInfo error = getSystemError(); if (error.errorCode != QSerialPort::ResourceError) error.errorCode = QSerialPort::ReadError; @@ -758,6 +759,8 @@ bool QSerialPortPrivate::readNotification() setReadNotificationEnabled(false); setError(error); return false; + } else if (readBytes == 0) { + return false; } newBytes = buffer.size() - newBytes; @@ -849,6 +852,9 @@ inline bool QSerialPortPrivate::initialize(QIODevice::OpenMode mode) if (mode & QIODevice::ReadOnly) setReadNotificationEnabled(true); + // flush IO buffers + clear(QSerialPort::AllDirections); + return true; } @@ -911,7 +917,7 @@ QSerialPortErrorInfo QSerialPortPrivate::getSystemError(int systemErrorCode) con case EBADF: error.errorCode = QSerialPort::ResourceError; break; -#ifdef Q_OS_OSX +#ifdef Q_OS_MACOS case ENXIO: error.errorCode = QSerialPort::ResourceError; break; @@ -992,7 +998,7 @@ bool QSerialPortPrivate::waitForReadOrWrite(bool *selectForRead, bool *selectFor if (checkWrite) pfd.events |= POLLOUT; - const int ret = qt_poll_msecs(&pfd, 1, msecs); + const int ret = qt_safe_poll(&pfd, 1, QDeadlineTimer(msecs)); if (ret < 0) { setError(getSystemError()); return false; diff --git a/src/serialport/qserialport_win.cpp b/src/serialport/qserialport_win.cpp index 5e7e0eb7..0bd6343e 100644 --- a/src/serialport/qserialport_win.cpp +++ b/src/serialport/qserialport_win.cpp @@ -533,6 +533,12 @@ bool QSerialPortPrivate::startAsyncRead() bool QSerialPortPrivate::_q_startAsyncWrite() { + if (handle == INVALID_HANDLE_VALUE) { + // Prevent a crash if the application incorrectly has not called open() before + // calling this (QTBUG-120412) + return false; + } + if (writeBuffer.isEmpty() || writeStarted) return true; diff --git a/src/serialport/qserialportinfo.cpp b/src/serialport/qserialportinfo.cpp index 094fbdad..be58f694 100644 --- a/src/serialport/qserialportinfo.cpp +++ b/src/serialport/qserialportinfo.cpp @@ -26,12 +26,20 @@ static_assert(sizeof(std::unique_ptr<QSerialPortInfoPrivate>) \inmodule QtSerialPort \since 5.1 - Use the static functions to generate a list of QSerialPortInfo - objects. Each QSerialPortInfo object in the list represents a single - serial port and can be queried for the port name, system location, - description, and manufacturer. The QSerialPortInfo class can also be - used as an input parameter for the setPort() method of the QSerialPort - class. + Use the static \l availablePorts() function to generate a list of + QSerialPortInfo objects. Each QSerialPortInfo object in the list represents + a single serial port and can be queried for the \l {portName}{port name}, + \l {systemLocation}{system location}, \l description, \l manufacturer, and + some other hardware parameters. The QSerialPortInfo class can also be + used as an input parameter for the \l {QSerialPort::}{setPort()} method of + the QSerialPort class. + + \section1 Example Usage + + The example code enumerates all available serial ports and prints their + parameters to console: + + \snippet doc_src_serialport.cpp enumerate_ports \sa QSerialPort */ diff --git a/src/serialport/qwinoverlappedionotifier.cpp b/src/serialport/qwinoverlappedionotifier.cpp index 06f2b614..3e85fd84 100644 --- a/src/serialport/qwinoverlappedionotifier.cpp +++ b/src/serialport/qwinoverlappedionotifier.cpp @@ -360,8 +360,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. @@ -381,6 +381,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/src/serialport/removed_api.cpp b/src/serialport/removed_api.cpp new file mode 100644 index 00000000..1d9fe2f7 --- /dev/null +++ b/src/serialport/removed_api.cpp @@ -0,0 +1,20 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#define QT_SERIALPORT_BUILD_REMOVED_API + +#include "qserialportglobal.h" + +QT_USE_NAMESPACE + +#if QT_SERIALPORT_REMOVED_SINCE(6, 7) + +#include "qserialport.h" +#include "qserialport_p.h" + +QBindable<bool> QSerialPort::bindableStopBits() +{ + return &d_func()->stopBits; +} + +#endif // QT_SERIALPORT_REMOVED_SINCE(6, 7) diff --git a/sync.profile b/sync.profile deleted file mode 100644 index bcd9ff65..00000000 --- a/sync.profile +++ /dev/null @@ -1,3 +0,0 @@ -%modules = ( - "QtSerialPort" => "$basedir/src/serialport", -); diff --git a/tests/auto/qserialport/CMakeLists.txt b/tests/auto/qserialport/CMakeLists.txt index 43394247..7b6514b9 100644 --- a/tests/auto/qserialport/CMakeLists.txt +++ b/tests/auto/qserialport/CMakeLists.txt @@ -11,4 +11,5 @@ qt_internal_add_test(tst_qserialport LIBRARIES Qt::SerialPort Qt::Test + Qt::TestPrivate ) diff --git a/tests/auto/qserialport/tst_qserialport.cpp b/tests/auto/qserialport/tst_qserialport.cpp index 9613208b..54d11369 100644 --- a/tests/auto/qserialport/tst_qserialport.cpp +++ b/tests/auto/qserialport/tst_qserialport.cpp @@ -1,7 +1,8 @@ // Copyright (C) 2014 Denis Shienkov <denis.shienkov@gmail.com> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtTest/QtTest> +#include <QtTest/private/qpropertytesthelper_p.h> #include <QtSerialPort/QSerialPort> #include <QtSerialPort/QSerialPortInfo> @@ -1267,142 +1268,85 @@ void tst_QSerialPort::bindingsAndProperties() // -- data bits - QProperty<QSerialPort::DataBits> dbProp(QSerialPort::DataBits::Data6); - QCOMPARE(dbProp.value(), QSerialPort::DataBits::Data6); - - sp.bindableDataBits().setBinding(Qt::makePropertyBinding(dbProp)); - QCOMPARE(sp.dataBits(), QSerialPort::DataBits::Data6); - - const QSignalSpy dataBitsChangedSpy(&sp, &QSerialPort::dataBitsChanged); - - dbProp = QSerialPort::DataBits::Data5; - QCOMPARE(sp.dataBits(), QSerialPort::DataBits::Data5); - QCOMPARE(dataBitsChangedSpy.size(), 1); - QCOMPARE(dataBitsChangedSpy.at(0).value(0).toInt(), QSerialPort::DataBits::Data5); - - dbProp.setBinding(sp.bindableDataBits().makeBinding()); - sp.setDataBits(QSerialPort::DataBits::Data8); - QCOMPARE(dbProp.value(), QSerialPort::DataBits::Data8); - - dbProp.setBinding([&] { return sp.dataBits(); }); - sp.setDataBits(QSerialPort::DataBits::Data7); - QCOMPARE(dbProp.value(), QSerialPort::DataBits::Data7); + QTestPrivate::testReadWritePropertyBasics(sp, QSerialPort::DataBits::Data6, + QSerialPort::DataBits::Data5, "dataBits"); + if (QTest::currentTestFailed()) { + qDebug("Failed property test for QSetialPort::dataBits"); + return; + } // -- parity - QProperty<QSerialPort::Parity> parityProp(QSerialPort::Parity::SpaceParity); - QCOMPARE(parityProp.value(), QSerialPort::Parity::SpaceParity); - - sp.bindableParity().setBinding(Qt::makePropertyBinding(parityProp)); - QCOMPARE(sp.parity(), QSerialPort::Parity::SpaceParity); - - const QSignalSpy parityChangedSpy(&sp, &QSerialPort::parityChanged); - - parityProp = QSerialPort::Parity::EvenParity; - QCOMPARE(sp.parity(), QSerialPort::Parity::EvenParity); - QCOMPARE(parityChangedSpy.size(), 1); - QCOMPARE(parityChangedSpy.at(0).value(0).toInt(), QSerialPort::Parity::EvenParity); - - parityProp.setBinding(sp.bindableParity().makeBinding()); - sp.setParity(QSerialPort::Parity::NoParity); - QCOMPARE(parityProp.value(), QSerialPort::Parity::NoParity); - - parityProp.setBinding([&] { return sp.parity(); }); - sp.setParity(QSerialPort::Parity::OddParity); - QCOMPARE(parityProp.value(), QSerialPort::Parity::OddParity); + QTestPrivate::testReadWritePropertyBasics(sp, QSerialPort::Parity::SpaceParity, + QSerialPort::Parity::EvenParity, "parity"); + if (QTest::currentTestFailed()) { + qDebug("Failed property test for QSetialPort::parity"); + return; + } // -- stop bits - QProperty<QSerialPort::StopBits> sbProp(QSerialPort::StopBits::OneAndHalfStop); - QCOMPARE(sbProp.value(), QSerialPort::StopBits::OneAndHalfStop); - - sp.bindableStopBits().setBinding(Qt::makePropertyBinding(sbProp)); - QCOMPARE(sp.stopBits(), QSerialPort::StopBits::OneAndHalfStop); - - const QSignalSpy stopBitsChangedSpy(&sp, &QSerialPort::stopBitsChanged); - - sbProp = QSerialPort::StopBits::OneStop; - QCOMPARE(sp.stopBits(), QSerialPort::StopBits::OneStop); - QCOMPARE(stopBitsChangedSpy.size(), 1); - QCOMPARE(stopBitsChangedSpy.at(0).value(0).toInt(), QSerialPort::StopBits::OneStop); + static_assert(std::is_same_v<decltype(sp.bindableStopBits()), + QBindable<QSerialPort::StopBits>>); - sbProp.setBinding(sp.bindableStopBits().makeBinding()); - sp.setStopBits(QSerialPort::StopBits::TwoStop); - QCOMPARE(sbProp.value(), QSerialPort::StopBits::TwoStop); - - sbProp.setBinding([&] { return sp.stopBits(); }); - sp.setStopBits(QSerialPort::StopBits::OneAndHalfStop); - QCOMPARE(sbProp.value(), QSerialPort::StopBits::OneAndHalfStop); + QTestPrivate::testReadWritePropertyBasics(sp, QSerialPort::StopBits::OneAndHalfStop, + QSerialPort::StopBits::TwoStop, "stopBits"); + if (QTest::currentTestFailed()) { + qDebug("Failed property test for QSetialPort::stopBits"); + return; + } // -- flow control - QProperty<QSerialPort::FlowControl> fcProp(QSerialPort::FlowControl::HardwareControl); - QCOMPARE(fcProp.value(), QSerialPort::FlowControl::HardwareControl); - - sp.bindableFlowControl().setBinding(Qt::makePropertyBinding(fcProp)); - QCOMPARE(sp.flowControl(), QSerialPort::FlowControl::HardwareControl); - - const QSignalSpy flowControlChangedSpy(&sp, &QSerialPort::flowControlChanged); - - fcProp = QSerialPort::FlowControl::NoFlowControl; - QCOMPARE(sp.flowControl(), QSerialPort::FlowControl::NoFlowControl); - QCOMPARE(flowControlChangedSpy.size(), 1); - QCOMPARE(flowControlChangedSpy.at(0).value(0).toInt(), QSerialPort::FlowControl::NoFlowControl); - - fcProp.setBinding(sp.bindableFlowControl().makeBinding()); - sp.setFlowControl(QSerialPort::FlowControl::SoftwareControl); - QCOMPARE(fcProp.value(), QSerialPort::FlowControl::SoftwareControl); - - fcProp.setBinding([&] { return sp.flowControl(); }); - sp.setFlowControl(QSerialPort::FlowControl::NoFlowControl); - QCOMPARE(fcProp.value(), QSerialPort::FlowControl::NoFlowControl); + QTestPrivate::testReadWritePropertyBasics(sp, QSerialPort::FlowControl::HardwareControl, + QSerialPort::FlowControl::SoftwareControl, + "flowControl"); + if (QTest::currentTestFailed()) { + qDebug("Failed property test for QSetialPort::flowControl"); + return; + } // -- error - QProperty<QSerialPort::SerialPortError> errorProp(QSerialPort::SerialPortError::PermissionError); - QCOMPARE(errorProp.value(), QSerialPort::SerialPortError::PermissionError); - - sp.bindableError().setBinding(Qt::makePropertyBinding(errorProp)); - QCOMPARE(sp.error(), QSerialPort::SerialPortError::NoError); - - const QSignalSpy errorChangedSpy(&sp, &QSerialPort::errorOccurred); - - // this shall not change the error, we do not have a public setter - errorProp = QSerialPort::SerialPortError::DeviceNotFoundError; - QCOMPARE(sp.error(), QSerialPort::SerialPortError::NoError); - QCOMPARE(errorChangedSpy.size(), 0); - - errorProp.setBinding(sp.bindableError().makeBinding()); - sp.clearError(); - QCOMPARE(errorProp.value(), QSerialPort::SerialPortError::NoError); - QCOMPARE(errorChangedSpy.size(), 1); - QCOMPARE(errorChangedSpy.at(0).value(0).toInt(), QSerialPort::SerialPortError::NoError); - - sp.setPortName(m_receiverPortName); - sp.open(QIODevice::ReadOnly); + QTestPrivate::testReadOnlyPropertyBasics( + sp, QSerialPort::SerialPortError::NoError, + QSerialPort::SerialPortError::UnsupportedOperationError, "error", + [&sp]() { sp.open(QIODevice::Truncate); }); + if (QTest::currentTestFailed()) { + qDebug("Failed property test for QSetialPort::error"); + return; + } // -- break enabled - QProperty<bool> beProp(false); - QCOMPARE(beProp.value(), false); - - sp.bindableIsBreakEnabled().setBinding(Qt::makePropertyBinding(beProp)); - QCOMPARE(sp.isBreakEnabled(), false); - - 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.setBinding(sp.bindableIsBreakEnabled().makeBinding()); - sp.setBreakEnabled(false); - QCOMPARE(beProp.value(), false); - - beProp.setBinding([&] { return sp.isBreakEnabled(); }); - sp.setBreakEnabled(true); - QCOMPARE(beProp.value(), true); + sp.setPortName(m_receiverPortName); + const bool portOpened = sp.open(QIODevice::ReadOnly); + + if (portOpened) { + // To test the binding loop we need to create another instance of + // QSerialPort, open it, and set breakEnabled == true as a default + // value, so use a custom lambda for that. + QTestPrivate::testReadWritePropertyBasics<QSerialPort, bool>( + sp, true, false, "breakEnabled", + [name = this->m_senderPortName]() { + auto ptr = std::make_unique<QSerialPort>(); + ptr->setPortName(name); + if (ptr->open(QIODevice::ReadOnly)) { + ptr->setBreakEnabled(true); + return ptr; + } + // skip binding loop test if we failed to open the port + return std::unique_ptr<QSerialPort>{}; + }); + if (QTest::currentTestFailed()) { + qDebug("Failed property test for QSetialPort::breakEnabled"); + return; + } + } else { + // setting isBreakEnabled() will return false and raise an error + sp.setBreakEnabled(true); + QCOMPARE(sp.error(), QSerialPort::SerialPortError::NotOpenError); + } } QTEST_MAIN(tst_QSerialPort) diff --git a/tests/auto/qserialportinfo/tst_qserialportinfo.cpp b/tests/auto/qserialportinfo/tst_qserialportinfo.cpp index b88531db..fb6d14c0 100644 --- a/tests/auto/qserialportinfo/tst_qserialportinfo.cpp +++ b/tests/auto/qserialportinfo/tst_qserialportinfo.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2014 Denis Shienkov <denis.shienkov@gmail.com> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtTest/QtTest> #include <QtSerialPort/QSerialPort> diff --git a/tests/auto/qserialportinfoprivate/tst_qserialportinfoprivate.cpp b/tests/auto/qserialportinfoprivate/tst_qserialportinfoprivate.cpp index 5af3f9f3..c9702d4a 100644 --- a/tests/auto/qserialportinfoprivate/tst_qserialportinfoprivate.cpp +++ b/tests/auto/qserialportinfoprivate/tst_qserialportinfoprivate.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2014 Denis Shienkov <denis.shienkov@gmail.com> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtTest/QtTest> @@ -33,7 +33,7 @@ void tst_QSerialPortInfoPrivate::canonical_data() QTest::newRow("Test1") << "COM1" << "COM1" << "\\\\.\\COM1"; QTest::newRow("Test2") << "\\\\.\\COM1" << "COM1" << "\\\\.\\COM1"; QTest::newRow("Test3") << "//./COM1" << "COM1" << "//./COM1"; -#elif defined(Q_OS_OSX) +#elif defined(Q_OS_MACOS) QTest::newRow("Test1") << "ttyS0" << "ttyS0" << "/dev/ttyS0"; QTest::newRow("Test2") << "cu.serial1" << "cu.serial1" << "/dev/cu.serial1"; QTest::newRow("Test3") << "tty.serial1" << "tty.serial1" << "/dev/tty.serial1"; diff --git a/tests/manual/CMakeLists.txt b/tests/manual/CMakeLists.txt new file mode 100644 index 00000000..3057e843 --- /dev/null +++ b/tests/manual/CMakeLists.txt @@ -0,0 +1,7 @@ +# Copyright (C) 2023 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +if(TARGET Qt::Widgets) + add_subdirectory(examples/sender) + add_subdirectory(examples/receiver) +endif() diff --git a/examples/serialport/receiver/CMakeLists.txt b/tests/manual/examples/receiver/CMakeLists.txt index 01fe292c..b50166ee 100644 --- a/examples/serialport/receiver/CMakeLists.txt +++ b/tests/manual/examples/receiver/CMakeLists.txt @@ -1,19 +1,13 @@ # Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause cmake_minimum_required(VERSION 3.16) project(receiver LANGUAGES CXX) -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/serialport/receiver") - find_package(Qt6 REQUIRED COMPONENTS Core Gui SerialPort Widgets) +qt_standard_project_setup() + qt_add_executable(receiver dialog.cpp dialog.h main.cpp @@ -30,9 +24,3 @@ target_link_libraries(receiver PRIVATE Qt::SerialPort Qt::Widgets ) - -install(TARGETS receiver - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/serialport/receiver/dialog.cpp b/tests/manual/examples/receiver/dialog.cpp index 51e18ea8..51e18ea8 100644 --- a/examples/serialport/receiver/dialog.cpp +++ b/tests/manual/examples/receiver/dialog.cpp diff --git a/examples/serialport/receiver/dialog.h b/tests/manual/examples/receiver/dialog.h index a32e1480..a32e1480 100644 --- a/examples/serialport/receiver/dialog.h +++ b/tests/manual/examples/receiver/dialog.h diff --git a/examples/serialport/receiver/main.cpp b/tests/manual/examples/receiver/main.cpp index f08a0eed..f08a0eed 100644 --- a/examples/serialport/receiver/main.cpp +++ b/tests/manual/examples/receiver/main.cpp diff --git a/examples/serialport/receiver/receiver.pro b/tests/manual/examples/receiver/receiver.pro index 3842f505..d3180061 100644 --- a/examples/serialport/receiver/receiver.pro +++ b/tests/manual/examples/receiver/receiver.pro @@ -10,6 +10,3 @@ HEADERS += \ SOURCES += \ main.cpp \ dialog.cpp - -target.path = $$[QT_INSTALL_EXAMPLES]/serialport/receiver -INSTALLS += target diff --git a/examples/serialport/sender/CMakeLists.txt b/tests/manual/examples/sender/CMakeLists.txt index 58cc8f8e..aac32863 100644 --- a/examples/serialport/sender/CMakeLists.txt +++ b/tests/manual/examples/sender/CMakeLists.txt @@ -1,19 +1,15 @@ # Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause cmake_minimum_required(VERSION 3.16) project(sender LANGUAGES CXX) -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/serialport/sender") find_package(Qt6 REQUIRED COMPONENTS Core Gui SerialPort Widgets) +qt_standard_project_setup() + qt_add_executable(sender dialog.cpp dialog.h main.cpp @@ -30,9 +26,3 @@ target_link_libraries(sender PRIVATE Qt::SerialPort Qt::Widgets ) - -install(TARGETS sender - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/serialport/sender/dialog.cpp b/tests/manual/examples/sender/dialog.cpp index d19ec888..d19ec888 100644 --- a/examples/serialport/sender/dialog.cpp +++ b/tests/manual/examples/sender/dialog.cpp diff --git a/examples/serialport/sender/dialog.h b/tests/manual/examples/sender/dialog.h index 0f049950..0f049950 100644 --- a/examples/serialport/sender/dialog.h +++ b/tests/manual/examples/sender/dialog.h diff --git a/examples/serialport/sender/main.cpp b/tests/manual/examples/sender/main.cpp index f08a0eed..f08a0eed 100644 --- a/examples/serialport/sender/main.cpp +++ b/tests/manual/examples/sender/main.cpp diff --git a/examples/serialport/sender/sender.pro b/tests/manual/examples/sender/sender.pro index 83cb7be8..f5fc421f 100644 --- a/examples/serialport/sender/sender.pro +++ b/tests/manual/examples/sender/sender.pro @@ -10,6 +10,3 @@ HEADERS += \ SOURCES += \ main.cpp \ dialog.cpp - -target.path = $$[QT_INSTALL_EXAMPLES]/serialport/sender -INSTALLS += target |