Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Serial port reading with QSerialPort : No such slot QObject...

Serial port reading with QSerialPort : No such slot QObject...

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
3 Posts 3 Posters 1.4k 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.
  • Q Offline
    Q Offline
    Quintinius
    wrote on last edited by
    #1

    Hello everyone,

    I'm trying to read data sent on a serial port using the QSerialPort library. The data are values that come from an Arduino card. After some research, I did the following blockcode which sets the serial port to read and then a signal connected to a slot to acquire the data. The'PortListener' function is then called in the main.

    PortListener::PortListener(const QString &portName)
    {
        this->port = new QSerialPort();
        port->open(QIODevice::ReadWrite);
        port->setPortName(portName);
        port->setBaudRate(QSerialPort::Baud9600);
        port->setDataBits(QSerialPort::Data8);
        port->setParity(QSerialPort::NoParity);
        port->setStopBits(QSerialPort::OneStop);
        port->setFlowControl(QSerialPort::NoFlowControl);
    
        connect(port, SIGNAL(readyRead()), this, SLOT(readyReadSlot()));
    }
    
    void PortListener::readyReadSlot()
    {
        while(!port->atEnd()){
            QByteArray data = port->readAll();
            qDebug() << "message :" << data;
        }
    }
    

    After running the program, I get an error message like "QObject::connect: No such slot QObject::readyReadSlot()" which seems to mean that no data is sent on the serial port. However, I did some tests with the examples provided by the QextSerialPort library and I am receiving the data well so the error will not come from there. I would still like to use QSerialPort.

    Does anyone have any idea where the problem might come from?

    J.HilkJ ODБOïO 2 Replies Last reply
    0
    • Q Quintinius

      Hello everyone,

      I'm trying to read data sent on a serial port using the QSerialPort library. The data are values that come from an Arduino card. After some research, I did the following blockcode which sets the serial port to read and then a signal connected to a slot to acquire the data. The'PortListener' function is then called in the main.

      PortListener::PortListener(const QString &portName)
      {
          this->port = new QSerialPort();
          port->open(QIODevice::ReadWrite);
          port->setPortName(portName);
          port->setBaudRate(QSerialPort::Baud9600);
          port->setDataBits(QSerialPort::Data8);
          port->setParity(QSerialPort::NoParity);
          port->setStopBits(QSerialPort::OneStop);
          port->setFlowControl(QSerialPort::NoFlowControl);
      
          connect(port, SIGNAL(readyRead()), this, SLOT(readyReadSlot()));
      }
      
      void PortListener::readyReadSlot()
      {
          while(!port->atEnd()){
              QByteArray data = port->readAll();
              qDebug() << "message :" << data;
          }
      }
      

      After running the program, I get an error message like "QObject::connect: No such slot QObject::readyReadSlot()" which seems to mean that no data is sent on the serial port. However, I did some tests with the examples provided by the QextSerialPort library and I am receiving the data well so the error will not come from there. I would still like to use QSerialPort.

      Does anyone have any idea where the problem might come from?

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by J.Hilk
      #2

      hi @Quintinius said in Serial port reading with QSerialPort : No such slot QObject...:
      you're using the olf (Qt4) syntax,

      connect(port, SIGNAL(readyRead()), this, SLOT(readyReadSlot()));

      using that synatx, you must mark functions that are slots, with the slots macro in the header file. Or it won't work at all

      public slots:
           void readyReadSlot();
      

      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      3
      • Q Quintinius

        Hello everyone,

        I'm trying to read data sent on a serial port using the QSerialPort library. The data are values that come from an Arduino card. After some research, I did the following blockcode which sets the serial port to read and then a signal connected to a slot to acquire the data. The'PortListener' function is then called in the main.

        PortListener::PortListener(const QString &portName)
        {
            this->port = new QSerialPort();
            port->open(QIODevice::ReadWrite);
            port->setPortName(portName);
            port->setBaudRate(QSerialPort::Baud9600);
            port->setDataBits(QSerialPort::Data8);
            port->setParity(QSerialPort::NoParity);
            port->setStopBits(QSerialPort::OneStop);
            port->setFlowControl(QSerialPort::NoFlowControl);
        
            connect(port, SIGNAL(readyRead()), this, SLOT(readyReadSlot()));
        }
        
        void PortListener::readyReadSlot()
        {
            while(!port->atEnd()){
                QByteArray data = port->readAll();
                qDebug() << "message :" << data;
            }
        }
        

        After running the program, I get an error message like "QObject::connect: No such slot QObject::readyReadSlot()" which seems to mean that no data is sent on the serial port. However, I did some tests with the examples provided by the QextSerialPort library and I am receiving the data well so the error will not come from there. I would still like to use QSerialPort.

        Does anyone have any idea where the problem might come from?

        ODБOïO Offline
        ODБOïO Offline
        ODБOï
        wrote on last edited by ODБOï
        #3

        @Quintinius said in Serial port reading with QSerialPort : No such slot QObject...:

        "QObject::connect: No such slot QObject::readyReadSlot()"

        Error is saying that the class QObject has no method public slot called readyReadSlot

        I still don't know why you have this error, but please try to use the new Signal/Slot syntax

        connect(port, &QSerialPort::readyRead, this, &PortListener::readyReadSlot);
        
        1 Reply Last reply
        1

        • Login

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