c++ - Qt: connect() 需要至少 4 个参数,但提供了 2 个

标签 c++ qt connect

我在这里错过了什么,为什么下面的例子给我编译时错误?

测试线.h:

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

测试线.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()

关于c++ - Qt: connect() 需要至少 4 个参数,但提供了 2 个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40351592/

相关文章:

sqlite - 我如何将数据从 SQLite 检索到 VB6?

c++ - 使用 GLM + Answer 将屏幕转换为 3D 世界坐标后结果不佳

c++ - 如何在 C++ 中计算函数的执行时间和 cpu 加速

C++ wininet,连接到weblogin,如何设置cookies?

C++/QT : Using constant pointer to private member as read-only data-sharing

c++ - 以正确的方式从您的位置找到最近的对象 QT c++

python - 如何在pyqt5中对按钮点击使用react

c++ - boost shared_ptr 运算符 =

c++ - 如何在类模板中使用 boost::enable_if

qt - 在插槽运行期间刷新/更新 GUI