Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Subclassing QSerialPort - can't connect to slot
QtWS25 Last Chance

[SOLVED] Subclassing QSerialPort - can't connect to slot

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 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.
  • F Offline
    F Offline
    frankiefrank
    wrote on last edited by
    #1

    I'm trying something that looks straight forward enough:

    This is my header:
    @
    class SerialPort : public QSerialPort
    {
    public:
    SerialPort(QObject *parent = 0);

    public slots:
    void handleReadyRead();
    };
    @

    And the implementation:
    @
    SerialPort::SerialPort(QObject *parent)
    : QSerialPort(parent)
    {
    // This connection fails.
    bool ok = connect(this, SIGNAL(readyRead()), this, SLOT(handleReadyRead()));
    }

    void SerialPort::handleReadyRead()
    {
    }
    @

    When debugging, I see this warning:
    QObject::connect: No such slot QSerialPort::handleReadyRead() in ..\serialport.cpp:6

    But I don't understand why this fails. And why the error message refers to a slot in the parent QSerialPort and not to my subclass, SerialPort.

    Could anyone spot what I'm doing wrong?

    "Roads? Where we're going, we don't need roads."

    1 Reply Last reply
    0
    • F Offline
      F Offline
      frankiefrank
      wrote on last edited by
      #2

      Ah I found the answer through this SO post:
      http://stackoverflow.com/questions/4322224/qt-slots-and-inheritance-why-is-my-program-trying-to-connect-to-the-parent-inst

      I needed to put the Q_OBJECT macro in my subclass to enable the signals and slots mechanism, even when subclassing a QObject subclass... Works now.

      "Roads? Where we're going, we don't need roads."

      1 Reply Last reply
      0

      • Login

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