Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. qt delegate connect signal lambda connection
Forum Updated to NodeBB v4.3 + New Features

qt delegate connect signal lambda connection

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 296 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    IknowQT
    wrote on 20 Apr 2022, 08:30 last edited by IknowQT
    #1
    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;
    				});
    
    J 1 Reply Last reply 20 Apr 2022, 08:37
    0
    • I IknowQT
      20 Apr 2022, 08:30
      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;
      				});
      
      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 20 Apr 2022, 08:37 last edited by
      #2

      @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*).

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      3

      1/2

      20 Apr 2022, 08:30

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved