qt delegate connect signal lambda connection
Solved
General and Desktop
-
QWidget* usrTableDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const { usrSetupLineEdit* pEdit = new usrSetupLineEdit(parent);//qobject_cast<usrSetupLineEdit*>(lineEdit); pEdit->SetOnlyNumber(true, true); pEdit->SetRange(m_min, m_max); pEdit->setAlignment(Qt::AlignCenter); emit UserDefine_EnableEditable(pEdit); return pEdit; } usrTableDelegate* a = static_cast<usrTableDelegate*>(this->ui.tableWidget->itemDelegate()); this->connect(a, &usrTableDelegate::UserDefine_EnableEditable, [](const usrSetupLineEdit* editor) { usrSetupLineEdit* lineEdit = const_cast<usrSetupLineEdit*>(editor); connect(lineEdit, &usrSetupLineEdit::UserDefineReturnPress, [](const usrSetupLineEdit* edit) { usrSetupLineEdit* eedit = const_cast<usrSetupLineEdit*>(edit); if (eedit->IsError()) { int a = 0; int b = 0; } //ValueValidateCheck(p); }); });
When the UserDefineReturnPress signal is received
Passing lineEdit as an argument and trying to operate according to isError.When I build, an error occurs.
"Return type of the slot is not compatible with the return type of the signal."
Signal and slot arguments are not compatible.please tell me how to connect signal with lambda
FYI, if I wire textChanged instead of UserDefineReturnPress it works fine.
connect(lineEdit, &QLineEdit::textChanged, [](const QString& text) { qDebug() << text; });
-
@IknowQT If you want to pass parameters to a lambda which are not part of the signal do it in the lambda capture list:
connect(lineEdit, &usrSetupLineEdit::UserDefineReturnPress, [edit]()
Above I assume that this usrSetupLineEdit you want to pass is named "edit".
There is also no need for that cast (edit IS already usrSetupLineEdit*).