QObject::connect - error: no matching function for call to ... ^



  • Hi;
    My Codes:
    mainwindow.h

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QMainWindow>
    #include <QMap>
    
    namespace Ui {
    class MainWindow;
    }
    
    class MainWindow : public QMainWindow
    {
      Q_OBJECT
    
    public:
      explicit MainWindow(QWidget *parent = 0);
      ~MainWindow();
    
    private:
      Ui::MainWindow *ui;
      QMap<QString, QString> changes;
    };
    
    #endif // MAINWINDOW_H
    
    

    mainwindow.cpp

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    
    MainWindow::MainWindow(QWidget *parent) :
      QMainWindow(parent),
      ui(new Ui::MainWindow)
    {
      ui->setupUi(this);
    
      connect(ui->lineEdit, SIGNAL(textChanged(QString)), [this](const QString& value) { changes["lineEdit"] = value; }); // I get error here.
    }
    
    MainWindow::~MainWindow()
    {
      delete ui;
    }
    

    I get this error message:

    /home/UserName/My Projects/project1/mainwindow.cpp:12: error: no matching function for call to 'MainWindow::connect(QLineEdit*&, const char*, MainWindow::MainWindow(QWidget*)::<lambda(const QString&)>)'
       connect(ui->lineEdit, SIGNAL(textChanged(QString)), [this](const QString& value) { changes["lineEdit"] = value; });
                                                                                                                        ^
    

    Error Message: Image Link
    Thanks.



  • You are mixing two connect syntaxes, you cannot use the old SIGNAL() way with lambdas.
    connect(ui->lineEdit, SIGNAL(textChanged(QString)), [this](const QString& value) { changes["lineEdit"] = value; });
    should become
    connect(ui->lineEdit, &QLineEdit::textChanged, [this](const QString& value) { changes["lineEdit"] = value; });



  • @VRonin Thanks. It is work.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.