From 10:00 CET Friday 22nd November we will adjust how the server works to deal with some recently reported problems. Therefore there may be a load problem, if you experience more problems than usual trying to access the forum then please PM AndyS or any of the moderators so they can inform me.

Arduino Serial Port Communications - Can't Open Arduino

  • Currently I'm working on a project with Qt that requires me to be able to read and write to an Arduino. Right now I'm using this code to communicate with the Arduino:

    //open and configure serialport

    But I've determined that the Arduino is not being opened even though I think I tell it to open in that code. I know that the Arduino is connected to the right port because Qt can recognize that Arduino is connected but won't open it and therefore can't read or write to it. I'm largely basing my serial port code on this one here:

    This code works fine when he does it, and I did everything he did on the serial port side of the code, so I don't understand what is wrong. Any help would be appreciated.

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    First thing to do is check whether open return true of false. If false, check what error you get. One other thing to check is whether you have the permissions to access the serial port ?

  • @MagicalJourney Did you have any luck? I also want to talk to an Arduino and every time I try to open the port I get the error message that "File exists" (QSerialPort::errorString).

  • may be try setDataTerminalReady(true);. This is some code I've written over a year ago. I don't remember why each line, but it worked.

    port = new QSerialPort(*portInfo);
    if (!port->open(QIODevice::ReadWrite)) {
    	qDebug() << QString("failed to connect: failed to open port %1").arg(port->errorString());
    	goto failed;
    if (!port->setBaudRate(115200)) {
    	qDebug() << QString("failed to connect: failed to setBaudRate(115200) %1").arg(port->errorString());
    	goto failed;
    if (!port->setStopBits(QSerialPort::OneStop)) {
    	qDebug() << QString("failed to connect: failed to set QSerialPort::OneStop %1").arg(port->errorString());
    	goto failed;
    if (!port->setParity(QSerialPort::NoParity)) {
    	qDebug() << QString("failed to connect: failed to set QSerialPort::NoParity %1").arg(port->errorString());
    	goto failed;
    if (!port->setDataBits(QSerialPort::Data8)) {
    	qDebug() << QString("failed to connect: failed to set QSerialPort::Data8 %1").arg(port->errorString());
    	goto failed;
    if (!port->isOpen()) {
    	goto failed;

  • This post is deleted!

  • Workaround: Start an application (QProcess) that pipes the serialport to a localhost socket.