Qt: connect() 需要至少 4 个参数,但提供了 2 个
Qt: connect() requires at least 4 arguments, but 2 were provided
我在这里错过了什么,为什么下面的例子给我编译时错误?
testline.h:
#include <QLineEdit>
class TestLine : public QLineEdit
{
Q_OBJECT
public:
TestLine(QWidget *parent = 0);
public slots:
virtual void on_textEdited(const QString&);
};
testline.cpp:
#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
}
错误信息:
../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
connect(this, SIGNAL(textEdited(const QString &)))
// 1 2 3 321
此时您所做的正是编译器输出所说的 - 您仅使用 2 个参数调用 connect()
。
我在这里错过了什么,为什么下面的例子给我编译时错误?
testline.h:
#include <QLineEdit>
class TestLine : public QLineEdit
{
Q_OBJECT
public:
TestLine(QWidget *parent = 0);
public slots:
virtual void on_textEdited(const QString&);
};
testline.cpp:
#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
}
错误信息:
../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
connect(this, SIGNAL(textEdited(const QString &)))
// 1 2 3 321
此时您所做的正是编译器输出所说的 - 您仅使用 2 个参数调用 connect()
。