I have a function (public slot)
void Parts::Testing(QString text)
{
ui_add_new_part->lineEdit_InvoiceNumber->setText(text);
}
that is connected to signal of QCompleter as
connect(completer_part_invoice, SIGNAL(activated(QString)),
this, SLOT(Testing(QString)));
The purpose of the above code is, whenever i use complete() function from QCompleter, the suggestions pop up on line edit and upon clicking a suggestion, that particular text should come on the line edit.
The above code works as I expect
Problem Since the function has only one statement I want to use lambda expression in the connect function itself. Thereby saving code length and Improving readibility. Upon googling I found this. Upon referring the site I wrote code like this
Try 1
connect(
completer_part_invoice, &QCompleter::activated,
[&]( const QString &text )
{
ui_add_new_part->lineEdit_InvoiceNumber->setText(text);
});
But Qt is throwing the error
error: no matching function for call to 'Parts::connect(QCompleter*&, <unresolved overloaded function type>, Parts::pop_Up_Invoices()::<lambda(const QString&)>)'
);
^
Try 2
connect(
completer_part_invoice, SIGNAL(activated(QString)),
[&]( const QString &text )
{
ui_add_new_part->lineEdit_InvoiceNumber->setText(text);
});
But Qt threw error
error: no matching function for call to 'Parts::connect(QCompleter*&, const char [20], Parts::pop_Up_Invoices()::<lambda(const QString&)>)'
});
^
What am I doing wrong?
Try3
As pointed in comments I also tried
connect(
completer_part_invoice, QOverload<const QString &>(&QCompleter::activated),
[&](const QString &text)->void
{
ui_add_new_part->lineEdit_InvoiceNumber->setText(text);
});
Error I got
error: no matching function for call to 'QOverload<const QString&>::QOverload(<unresolved overloaded function type>)'
completer_part_invoice, QOverload<const QString &>(&QCompleter::activated),
^