user1829358 user1829358 - 1 year ago 123
C++ Question

Qt: connect() requires at least 4 arguments, but 2 were provided

What am I missing here, why is the following example giving me compile-time errors?


#include <QLineEdit>
class TestLine : public QLineEdit
TestLine(QWidget *parent = 0);
public slots:
virtual void on_textEdited(const QString&);


#include "testline.h"
TestLine::TestLine(QWidget *parent) : QLineEdit(parent)
connect(this, SIGNAL(textEdited(const QString &))), this,
SLOT(on_textEdited(const QString &)));

void TestLine::on_textEdited(const QString &text)
// something

error message:

../testline.cpp:7:5: error

: no matching member function for call to 'connect'
connect(this, SIGNAL(textEdited(const QString &))), this,
../../../Qt/5.7/clang_64/lib/QtCore.framework/Headers/qobject.h:219:43: note: candidate function template not viable: requires at least 4 arguments, but 2 were provided

Answer Source
connect(this, SIGNAL(textEdited(const QString &)))
//     1            2          3               321

At this point you are doing what exactly the compiler output says - you are calling connect() with only 2 parameters.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download