QIODevice::write (QSerialPort): device not open
Unsolved
General and Desktop
-
When i debug, it says command aborted. I couldnt find my mistake
#include "mainwindow.h" #include "ui_mainwindow.h" #include <QSerialPort> #include <QDebug> QSerialPort *serial; MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); serial = new QSerialPort(this); serial->setPortName("com4"); serial->setBaudRate(QSerialPort::Baud9600); serial->setDataBits(QSerialPort::Data8); serial->setParity(QSerialPort::NoParity); serial->setStopBits(QSerialPort::OneStop); serial->setFlowControl(QSerialPort::NoFlowControl); serial->open(QIODevice::ReadWrite); serial->write("its working"); connect(serial, SIGNAL(readyRead()), this, SLOT(serialReceived())); } MainWindow::~MainWindow() { delete ui; serial->close(); } void MainWindow::serialReceived() { QByteArray ba; ba=serial->readAll(); ui->label->setText(ba); qDebug() << ba; }
-
@suslucoder said in QIODevice::write (QSerialPort): device not open:
serial->open(QIODevice::ReadWrite);
Check whether open() succeeded.
-
Hi,
Port already opened in another application.
Not enough user rights to access it.There's an error method that will give you more information.
-
@suslucoder are you sure
com4
is the correct name ? something seems of, I would suggest using https://doc.qt.io/qt-5/qserialportinfo.html
to query for the correct port and port name