C++ Qt:connect()至少需要4个参数,但提供了2个
我在这里遗漏了什么,为什么下面的例子给了我编译时错误 testline.h:C++ Qt:connect()至少需要4个参数,但提供了2个,c++,qt,connect,C++,Qt,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 <QLineEdit>
class TestLine : public QLineEdit
{
Q_OBJECT
public:
TestLine(QWidget *parent = 0);
public slots:
virtual void on_textEdited(const QString&);
};
错误消息:
../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
此时,您正在执行编译器输出所说的操作—您只需使用2个参数调用connect()
此时,您正在执行编译器输出所说的操作-您只使用2个参数调用
connect()
。SIGNAL(textEdited(const QString&))
太多的近亲关系。您有太多的近亲关系。最好仔细检查这些括号…因为您使用的是Qt 5(从输出中选择5.7),请开始使用,它可能已经解决了这个问题,因为您没有所有的大括号:connect(this,&TestLine::textcedited,this,&TestLine::on_textcedited)代码>如果您使用Qt4的connect
语法(为什么?),您应该更喜欢规范化签名。在您的情况下,信号(textEdit(QString))
。最上面的引用和常量应该被删除,所有不必要的空格也必须被删除。SIGNAL(textcedited(const QString&))
一个太多的近亲关系。你有一个太多了)最好仔细检查那些括号…因为你正在使用Qt 5(从你的输出中选择5.7),开始使用,它可能已经解决了这个问题,因为您没有所有的大括号:connect(this,&TestLine::textcedited,this,&TestLine::on_textcedited)代码>如果您使用Qt4的connect
语法(为什么?),您应该更喜欢规范化签名。在您的情况下,信号(textEdit(QString))
。应该删除最上面的引用和常量,还必须删除所有不必要的空格。
../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