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. QIODevice::write: device not open
QtWS25 Last Chance

QIODevice::write: device not open

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 10.1k Views
  • 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.
  • M Offline
    M Offline
    Matthacker
    wrote on 24 Nov 2014, 14:25 last edited by
    #1

    Hi

    I have a problem with setting up my connection to a COM port have been stuck for awhile now hope you can help me.

    Do I have to have my mbed controller connected for it to work ?

    when i run my code it says:

    bq.
    Serial NOT Opened
    error code = 1
    error string = "No such file or directory"
    QIODevice::write: device not open

    the code I have is:
    @

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include "modify_scenario.h"
    #include <QSerialPort>
    #include <QDebug>
    #include <QPushButton>
    #include <QWidget>

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {

     ui->setupUi(this);
    
     serial = new QSerialPort(this);
     serial->setPortName("COM2");
     if(serial->open(QIODevice::ReadWrite))
     {
         qDebug("Serial Opened");
         serial->setBaudRate(QSerialPort::Baud9600);
         serial->setDataBits(QSerialPort::Data8);
         serial->setParity(QSerialPort::NoParity);
         serial->setStopBits(QSerialPort::OneStop);
         serial->setFlowControl(QSerialPort::NoFlowControl);
     }
     else
     {
         qDebug ("Serial NOT Opened");
         qDebug() << "error code = " << serial->error();
         qDebug() << "error string = " << serial->errorString();
     }
    
     connect(serial,SIGNAL(readyRead()),this,SLOT(serialReceived()));
    

    @

    for the connect: (serialReceived())

    @
    void MainWindow::serialReceived()
    {
    QByteArray ba;
    ba = serial -> readAll();
    ui->label->setText(ba);
    qDebug() << ba;
    }
    @

    and in the header I have in private slots

    @

    void serialReceived();
    @

    and in private

    @

    private:
    Ui::MainWindow *ui;
    Modify_Scenario *modify;
    int counter;
    QSerialPort *serial;
    @

    really hope you can help me :)

    Regards Alex.

    1 Reply Last reply
    0
    • K Offline
      K Offline
      kuzulis
      Qt Champions 2020
      wrote on 24 Nov 2014, 15:55 last edited by
      #2

      This means that COM2 is not exists on your PC (you can check it in Device Manager).

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Matthacker
        wrote on 24 Nov 2014, 18:55 last edited by
        #3

        Hi Kuzulis

        Yes that is correct, checked it already.

        does that mean I have to setup a virtual com port?
        and how do I do that ?

        if I input my device to my computer, then my computer detects a COM port, but wanted to test it without the device.

        Alex.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 24 Nov 2014, 21:22 last edited by
          #4

          Hi and welcome to devnet,

          Do you mean that you would like to make your code run even when there's no serial port available ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Matthacker
            wrote on 24 Nov 2014, 21:24 last edited by
            #5

            used Eltima's virtual COM port to setup a virtual port and tested it with tera term and it works now :)

            1 Reply Last reply
            0

            5/5

            24 Nov 2014, 21:24

            • Login

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