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. Signal returnPressed() doesn't work in setModelData
Forum Updated to NodeBB v4.3 + New Features

Signal returnPressed() doesn't work in setModelData

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 1.7k 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.
  • G Offline
    G Offline
    gabor53
    wrote on last edited by
    #1

    Hi,
    I'm trying to use signal returnPressed() in setModelData:

    void myDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
    {
        QLineEdit *edit = qobject_cast<QLineEdit*>(editor);
    
        if(edit)
            {
                model->setData (index,edit->text ());
                QVariant f(index.data(Qt::DisplayRole));
                QString modified;
                modified = f.toString ();
                qDebug() << "Modified: " << modified;
                connect(edit,SIGNAL(returnPressed()), this,SLOT(saveChangedItem()));
    
                return;
            }
    }
    

    Everything works fine but when the connect processed nothing happens (it does not go to saveChangedItem(). Please point me to the right direction to make this work. Thank you.

    jsulmJ 1 Reply Last reply
    0
    • G gabor53

      Hi,
      I'm trying to use signal returnPressed() in setModelData:

      void myDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
      {
          QLineEdit *edit = qobject_cast<QLineEdit*>(editor);
      
          if(edit)
              {
                  model->setData (index,edit->text ());
                  QVariant f(index.data(Qt::DisplayRole));
                  QString modified;
                  modified = f.toString ();
                  qDebug() << "Modified: " << modified;
                  connect(edit,SIGNAL(returnPressed()), this,SLOT(saveChangedItem()));
      
                  return;
              }
      }
      

      Everything works fine but when the connect processed nothing happens (it does not go to saveChangedItem(). Please point me to the right direction to make this work. Thank you.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @gabor53 Are you aware that connect() does not call the slot? It just connect the signal to the slot. The slot is called when the signal appears. That means

      connect(edit,SIGNAL(returnPressed()), this,SLOT(saveChangedItem()));
      

      will not call saveChangedItem().
      saveChangedItem() will be called as soon as returnPressed() is emitted in edit.
      So, is the signal emitted?
      To be sure connect() succeeded you should print out its return value:

      qDebug() << connect(edit,SIGNAL(returnPressed()), this,SLOT(saveChangedItem()));
      

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

      1 Reply Last reply
      3
      • Pradeep KumarP Offline
        Pradeep KumarP Offline
        Pradeep Kumar
        wrote on last edited by
        #3

        Hi,

        Provide the debug statement and check the return value, to ensure the signal is emitted or not,
        and connect() statements establish connection between two objects, and will not call slot until the signal of one object is emitted.

        bool   value =  << connect(edit,SIGNAL(returnPressed()), this,SLOT(saveChangedItem()));
        
        qDebug () << value << endl;
        

        Sample Program : to ensure signal is emitted or not.

        m_edit = new QLineEdit;
        m_label = new QLabel
        
        value =  connect(m_edit,SIGNAL(returnPressed()),this,SLOT(getData()),Qt::UniqueConnection);
        

        void LineEDitSignal::getData()
        {
        qDebug () << value;

            m_label->setText(m_edit->text());
            qDebug () << "lineedit value :" << m_edit->text() << endl;
        

        }

        Thanks,

        Pradeep Kumar
        Qt,QML Developer

        1 Reply Last reply
        2

        • Login

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