Important: Please read the Qt Code of Conduct -

SIGNAL SLOT problem: Object::connect: No such slot

  • I write the code as below


    #include <QLineEdit>
    #include <QDebug>
    class EnglishEditLine:public QLineEdit
        QString getEnglishword() const;
        void setEnglishword(const QString &value);
        QString englishword;
    public slots:
        void on_englishEditLine_textEdited(const QString &arg);


    #include "englisheditline.h"
        QObject::connect(this, SIGNAL(textChanged ( const QString &)), this,  SLOT(on_englishEditLine_textEdited(const QString &)) );
    QString EnglishEditLine::getEnglishword() const
        return englishword;
    void EnglishEditLine::setEnglishword(const QString &value)
        englishword = value;
    void EnglishEditLine::on_englishEditLine_textEdited(const QString &arg)
        qDebug()<< this->text();

    but it ends up with the following errors

    QMetaObject::connectSlotsByName: No matching signal for on_lineEdit_textEdited(QString)
    Object::connect: No such slot QLineEdit::on_englishEditLine_textEdited(const QString &)

  • Moderators

    Hi, welcome to devnet.

    Since you're using signals and slots you're missing Q_OBJECT macro in your class declaration.

    Btw. It might be good idea to switch to the new connect syntax. It doesn't require to list params, it's not as easy to make a mistake and it gives errors at compile time instead of runtime messages that can be missed:

    connect(this, &EnglishEditLine::textChanged, this, &EnglishEditLine::on_englishEditLine_textEdited);

    Btw.2 Since your class is a widget it should really take a parent parameter in its constructor:

    EnglishEditLine(QWidget* parent = nullptr);

    and call base in the imlementation:

    EnglishEditLine::EnglishEditLine(QWidget* parent) : QLineEdit(parent) { ... }

    Btw.3 Avoid including unnecessary things in the headers. They pollute other files and increase build times (QDebug in this case can go into the .cpp)

Log in to reply