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. SIGNAL SLOT problem: Object::connect: No such slot
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.9k Views 2 Watching
  • 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.
  • V Offline
    V Offline
    VictorZhang
    wrote on last edited by
    #1

    I write the code as below

    englisheditline.h

    #ifndef ENGLISHEDITLINE_H
    #define ENGLISHEDITLINE_H
    
    #include <QLineEdit>
    #include <QDebug>
    
    class EnglishEditLine:public QLineEdit
    {
    public:
        EnglishEditLine();
        ~EnglishEditLine();
        QString getEnglishword() const;
        void setEnglishword(const QString &value);
    
    private:
        QString englishword;
    
    public slots:
        void on_englishEditLine_textEdited(const QString &arg);
    
    };
    
    #endif // ENGLISHEDITLINE_H
    

    englisheditline.cpp

    #include "englisheditline.h"
    
    EnglishEditLine::EnglishEditLine()
    {
        QObject::connect(this, SIGNAL(textChanged ( const QString &)), this,  SLOT(on_englishEditLine_textEdited(const QString &)) );
    }
    
    EnglishEditLine::~EnglishEditLine()
    {
    
    }
    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 &)
    
    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by Chris Kawa
      #2

      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)

      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