I've downloaded the program com0com and created 3 pairs of virtual coms. To test such coms, I downloaded Termite, which open, receive, transmit and close every pair successfully. So far so good.
However, in my QT application, I can't open any of the virtual coms (I don't have a actual port so I haven't tested).
My code:
#include <QSerialPort>
#include <QMessageBox>
#include <QInputDialog>
#include <QSerialPortInfo>
#include <QDebug>
ui->setupUi(this);
QSerialPort *serial = new QSerialPort(this);
QString port;
QStringList ListaDePortas;
QList<QSerialPortInfo> AllPorts(QSerialPortInfo::availablePorts());
bool ok;
if((AllPorts.isEmpty()))
{
QMessageBox::critical(this,"Erro","Nenhuma porta serial encontrada!");
exit(1);
}
for(int i=0;i<AllPorts.size();i++)
ListaDePortas.push_back(AllPorts[i].portName());
port = QInputDialog::getItem(this, "Porta Serial",
"Escolha uma porta serial para conectar:", ListaDePortas, 0, false, &ok);
if(!ok)
{
QMessageBox::warning(this,"Atenção","Nenhuma porta serial selecionada. O funcionamento do programa "
"depende da conexão serial.");
exit(1);
}
serial->setPortName(port);
qDebug() << serial->portName();
if(!serial->open(QIODevice::ReadWrite))
{
QMessageBox::critical(this,"Erro",serial->errorString());
exit(1);
}
qDebug() << "Porta conectada!";
serial->write("Test\r");
serial->flush();
serial->close();
exit(0);
The error message I receive is in portuguese (Even though my QT is in english). It translates to system cannot find the path specified
.
Any clues on what may be causing this? Thanks in advance!
EDIT 1 - Bonus:
This is my Application Output
:
Starting C:\Users\socc\Documents\Qt\build-VComTest-Desktop_Qt_5_10_0_MinGW_32bit-Debug\debug\VComTest.exe...
setGeometry: Unable to set geometry 116x30+94+105 on QWidgetWindow/'QInputDialogClassWindow'. Resulting geometry: 212x90+94+105 (frame: 8, 30, 8, 8, custom margin: 0, 0, 0, 0, minimum size: 212x90, maximum size: 524287x90).
"VCOM1"
C:/Users/socc/Documents/Qt/build-VComTest-Desktop_Qt_5_10_0_MinGW_32bit-Debug/debug/VComTest.exe
exited with code 1
I would also like to know why my QInputDialog
is producing that error. But that's just a bonus, not necessary for the question.
For anyone having troubles with this, open the com0com
setup, now, select the option Use Port Class on your virtual port pair. Use it for both ports in the pair.
I still do not know why that's the problem, specially since other terminals opened the port with no trouble. But that solved for me. If anyone get more information, feel free to post it.