C++ 如何将从QLineEdit更改的信号值连接到Qt中的自定义插槽

C++ 如何将从QLineEdit更改的信号值连接到Qt中的自定义插槽,c++,qt,signals-slots,qlineedit,C++,Qt,Signals Slots,Qlineedit,我需要以编程方式将valueChanged信号从QLineEdit连接到自定义插槽。我知道如何使用Qt Designer进行连接,并使用图形界面进行连接,但我希望以编程方式进行连接,以便了解更多有关信号和插槽的信息 这就是我所拥有的不起作用的东西 .cpp文件 // constructor connect(myLineEdit, SIGNAL(valueChanged(static QString)), this, SLOT(customSlot())); void MainWindow::c

我需要以编程方式将valueChanged信号从QLineEdit连接到自定义插槽。我知道如何使用Qt Designer进行连接,并使用图形界面进行连接,但我希望以编程方式进行连接,以便了解更多有关信号和插槽的信息

这就是我所拥有的不起作用的东西

.cpp文件

// constructor
connect(myLineEdit, SIGNAL(valueChanged(static QString)), this, SLOT(customSlot()));

void MainWindow::customSlot()
{
    qDebug()<< "Calling Slot";
}
我错过了什么


感谢
QLineEdit
似乎没有
valueChanged
信号,但
textChanged
(有关支持的信号的完整列表,请参阅Qt文档)。 您还需要更改
connect()
函数调用。应该是:

connect(myLineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(customSlot()));
如果您需要插槽中新文本值的句柄,您可以将其定义为
customSlot(const QString&newValue)
,这样您的连接将如下所示:

connect(myLineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(customSlot(const QString &)));

将值更改为textChanged,将静态QString更改为const QString&并工作。我不知道我是怎么错过的,特别是静态QString(哇),非常感谢。还非常感谢第二个示例,因为我还想知道参数的用法。非常感谢
connect(myLineEdit,&QLineEdit::textChanged,this,&MainWindow::customSlot)
connect(myLineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(customSlot(const QString &)));