Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. open(QIODevice::ReadWrite) fails with QSerialPort::UnsupportedOperationError (10)
Qt 6.11 is out! See what's new in the release blog

open(QIODevice::ReadWrite) fails with QSerialPort::UnsupportedOperationError (10)

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 969 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    PradeepCK
    wrote on last edited by PradeepCK
    #1

    Hello everyone,

    I am new to Qt.

    I am getting this error: QSerialPort::UnsupportedOperationError (10) when I try to open the serial port .

    Below is the code snippet where I am seeing the error:

    Header file:

        typedef struct {
            QString data;
            QSerialPort::BaudRate baudRate;
        } struct_BaudRate;
    
        const struct_BaudRate baudRates[7] = {
            {" "     , QSerialPort::UnknownBaud},
            {"9600"  , QSerialPort::Baud9600},
            {"19200" , QSerialPort::Baud19200},
            {"38400" , QSerialPort::Baud38400},
            {"57600" , QSerialPort::Baud57600},
            {"115200", QSerialPort::Baud115200},
            {"Custom", QSerialPort::UnknownBaud}
        };
    
    
        typedef struct {
            QString data;
            QSerialPort::DataBits dataBits;
        } struct_DataBits;
    
        const struct_DataBits dataBits[4] = {
            {"5", QSerialPort::Data5},
            {"6", QSerialPort::Data6},
            {"7", QSerialPort::Data7},
            {"8", QSerialPort::Data8},
        };
    
    
        typedef struct {
            QString data;
            QSerialPort::Parity Parity;
        } struct_Parity;
    
        const struct_Parity parity[5] = {
            {"None" , QSerialPort::NoParity},
            {"Even" , QSerialPort::EvenParity},
            {"Odd"  , QSerialPort::OddParity},
            {"Mark" , QSerialPort::MarkParity},
            {"Space", QSerialPort::SpaceParity}
        };
    
    
        typedef struct {
            QString data;
            QSerialPort::StopBits StopBits;
        } struct_StopBits;
    
        const struct_StopBits stopBits[3] = {
            {"1", QSerialPort::OneStop},
            {"1.5", QSerialPort::OneAndHalfStop},
            {"2", QSerialPort::TwoStop}
        };
    
    
        typedef struct {
            QString data;
            QSerialPort::FlowControl FlowControl;
        } struct_FlowControl;
    
        const struct_FlowControl flowControl[3] = {
            {"None", QSerialPort::NoFlowControl},
            {"RTS/CTS", QSerialPort::HardwareControl},
            {"XON/XOFF", QSerialPort::SoftwareControl}
        };
    
    
        typedef struct {
            QString Port;
            QString Description;
            QString Manufacturer;
            QString SerialNum;
            QString Location;
            QString VendorID;
            QString ProductID;
        }struct_COMDetails;
    
    

    openSerialPort():

    void MainWindow::openSerialPort()
    {
        serialData = new QSerialPort();
        serialData->setPortName(ui->combo_commPort->currentText());
        serialData->setBaudRate(static_cast<QSerialPort::BaudRate>(baudRates[ui->combo_BaudRate->currentIndex()].baudRate));
        serialData->setDataBits(static_cast<QSerialPort::DataBits>(dataBits[ui->combo_DataBits->currentIndex()].dataBits));
        serialData->setParity(static_cast<QSerialPort::Parity>(parity[ui->combo_Parity->currentIndex()].Parity));
        serialData->setStopBits(static_cast<QSerialPort::StopBits>(stopBits[ui->combo_StopBits->currentIndex()].StopBits));
        serialData->setFlowControl(static_cast<QSerialPort::FlowControl>(flowControl[ui->combo_FlowControl->currentIndex()].FlowControl));
    
        if (serialData->open(QIODevice::ReadWrite)) {
            ui->button_connect->setDisabled(true);
        } else {
            QSerialPort::SerialPortError strTempError = serialData->error();
            QMessageBox::critical(this, tr("Error"), serialData->errorString());
        }
    
    Pablo J. RoginaP 1 Reply Last reply
    0
    • P Offline
      P Offline
      PradeepCK
      wrote on last edited by
      #2

      This problem is solved now.
      It was my mistake in giving incorrect index for Baud rates and other attributes.

      I will be closing this topic.

      1 Reply Last reply
      0
      • P PradeepCK

        Hello everyone,

        I am new to Qt.

        I am getting this error: QSerialPort::UnsupportedOperationError (10) when I try to open the serial port .

        Below is the code snippet where I am seeing the error:

        Header file:

            typedef struct {
                QString data;
                QSerialPort::BaudRate baudRate;
            } struct_BaudRate;
        
            const struct_BaudRate baudRates[7] = {
                {" "     , QSerialPort::UnknownBaud},
                {"9600"  , QSerialPort::Baud9600},
                {"19200" , QSerialPort::Baud19200},
                {"38400" , QSerialPort::Baud38400},
                {"57600" , QSerialPort::Baud57600},
                {"115200", QSerialPort::Baud115200},
                {"Custom", QSerialPort::UnknownBaud}
            };
        
        
            typedef struct {
                QString data;
                QSerialPort::DataBits dataBits;
            } struct_DataBits;
        
            const struct_DataBits dataBits[4] = {
                {"5", QSerialPort::Data5},
                {"6", QSerialPort::Data6},
                {"7", QSerialPort::Data7},
                {"8", QSerialPort::Data8},
            };
        
        
            typedef struct {
                QString data;
                QSerialPort::Parity Parity;
            } struct_Parity;
        
            const struct_Parity parity[5] = {
                {"None" , QSerialPort::NoParity},
                {"Even" , QSerialPort::EvenParity},
                {"Odd"  , QSerialPort::OddParity},
                {"Mark" , QSerialPort::MarkParity},
                {"Space", QSerialPort::SpaceParity}
            };
        
        
            typedef struct {
                QString data;
                QSerialPort::StopBits StopBits;
            } struct_StopBits;
        
            const struct_StopBits stopBits[3] = {
                {"1", QSerialPort::OneStop},
                {"1.5", QSerialPort::OneAndHalfStop},
                {"2", QSerialPort::TwoStop}
            };
        
        
            typedef struct {
                QString data;
                QSerialPort::FlowControl FlowControl;
            } struct_FlowControl;
        
            const struct_FlowControl flowControl[3] = {
                {"None", QSerialPort::NoFlowControl},
                {"RTS/CTS", QSerialPort::HardwareControl},
                {"XON/XOFF", QSerialPort::SoftwareControl}
            };
        
        
            typedef struct {
                QString Port;
                QString Description;
                QString Manufacturer;
                QString SerialNum;
                QString Location;
                QString VendorID;
                QString ProductID;
            }struct_COMDetails;
        
        

        openSerialPort():

        void MainWindow::openSerialPort()
        {
            serialData = new QSerialPort();
            serialData->setPortName(ui->combo_commPort->currentText());
            serialData->setBaudRate(static_cast<QSerialPort::BaudRate>(baudRates[ui->combo_BaudRate->currentIndex()].baudRate));
            serialData->setDataBits(static_cast<QSerialPort::DataBits>(dataBits[ui->combo_DataBits->currentIndex()].dataBits));
            serialData->setParity(static_cast<QSerialPort::Parity>(parity[ui->combo_Parity->currentIndex()].Parity));
            serialData->setStopBits(static_cast<QSerialPort::StopBits>(stopBits[ui->combo_StopBits->currentIndex()].StopBits));
            serialData->setFlowControl(static_cast<QSerialPort::FlowControl>(flowControl[ui->combo_FlowControl->currentIndex()].FlowControl));
        
            if (serialData->open(QIODevice::ReadWrite)) {
                ui->button_connect->setDisabled(true);
            } else {
                QSerialPort::SerialPortError strTempError = serialData->error();
                QMessageBox::critical(this, tr("Error"), serialData->errorString());
            }
        
        Pablo J. RoginaP Offline
        Pablo J. RoginaP Offline
        Pablo J. Rogina
        wrote on last edited by
        #3

        @PradeepCK said in open(QIODevice::ReadWrite) fails with QSerialPort::UnsupportedOperationError (10):

        typedef struct {
        QString data;
        QSerialPort::BaudRate baudRate;
        } struct_BaudRate;
        const struct_BaudRate baudRates[7] = {
        {" " , QSerialPort::UnknownBaud},
        {"9600" , QSerialPort::Baud9600},
        {"19200" , QSerialPort::Baud19200},
        {"38400" , QSerialPort::Baud38400},
        {"57600" , QSerialPort::Baud57600},
        {"115200", QSerialPort::Baud115200},
        {"Custom", QSerialPort::UnknownBaud}
        };

        Just in case, you may want to use QComboBox::itemData to avoid defining structs/arrays that hold values (i.e. baud rate) related to every item in the combo list.

        Upvote the answer(s) that helped you solve the issue
        Use "Topic Tools" button to mark your post as Solved
        Add screenshots via postimage.org
        Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        2

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved