Nominate our 2022 Qt Champions!

QSerial - Can't read Arduino serial data

  • Hello!

    This is my first project using Qt and Arduino together. I'm trying to read and write data using a GUI and Arduino Uno, but I don't know what is happening.

    I want to click on a pushButton and receive the data that is on Serial. My code is not accessing readSerial and I believe that the problem is on the SIGNAL(readyRead()).

    void MainWindow::on_pushButton_clicked()
        arduino_is_available = false;
        arduino_port_name = "";
        arduino = new QSerialPort;
        foreach(const QSerialPortInfo &serialPortInfo, QSerialPortInfo::availablePorts()){
            if(serialPortInfo.hasVendorIdentifier() && serialPortInfo.hasProductIdentifier()){
                if(serialPortInfo.vendorIdentifier() == arduino_uno_vendor_id){
                    if(serialPortInfo.productIdentifier() == arduino_uno_product_id){
                        arduino_port_name = serialPortInfo.portName();
                        arduino_is_available = true;
            // open and configure the serialport
            QObject::connect(arduino, SIGNAL(readyRead()), this, SLOT(readSerial()));
            // give error message if not available
            QMessageBox::warning(this, "Port error", "Couldn't find the Arduino!");
    void MainWindow::readSerial(){
        qDebug() << "Teste 1";
        QByteArray daraSerial = arduino->readAll();
        serialBuffer += QString::fromStdString(daraSerial.toStdString());
        //std::cout << serialBuffer.toStdString();
        qDebug() << "Teste 2";
        qDebug() << serialBuffer;
        qDebug() << daraSerial;

    My Arduino code is just a loop with Serial.print("a"); and a delay.

    I have no idea how to solve this. I read some posts on the forum and didn't find something that solves my problem.

    What am I doing wrong?

    QObject::connect(arduino, SIGNAL(readyRead()), this, SLOT(readSerial())); is returning true.

    Thank you!

  • Moderators

    what Qt version are you using ? if it's below 12.6 or 13.2 you'll have to update, as the Serialport module had a bug in some versions.

  • I'm using 5.12.5. I'll try to update.

  • @J-Hilk Fixed! Thank you!

  • @J-Hilk Thanks man, your answer saved my time also,
    I had Qt 5.13.1 and serial read was not working, I updated to 5.14.0 and now it works.

Log in to reply