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. Using QTableView/QStyledItemDelegate Issue w/closeAndCommitEditor() coredump
QtWS25 Last Chance

Using QTableView/QStyledItemDelegate Issue w/closeAndCommitEditor() coredump

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 909 Views
  • 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.
  • S Offline
    S Offline
    ShawnZ
    wrote on last edited by
    #1

    Qt5
    I am using an example straight out the book 'Advanced Qt Programming'

    Have a cell in QTableView that when 'double click' generates
    a QLineEdit widget where I override the QStyledItemDelegate::createEditor(),
    setEditorData(), setModelData() functions. Everything is working fine. However,
    the 'core dump' situations arises when the user types in something that is
    not allowed ( i.e. certain text words are reserved ) - So I need to notify
    the user with a QMessageBox() that this text is reserved. I am not sure
    why this is causing the problem:

    Here is the code excerpts to show what I am doing:
    The core dump occurs in the function closeAndCommitEditorLE()
    which is called when the user hits Return in the QLineEdit editor.

    It only occurs after a call to issueDuplicateNameWarning() is called
    which popups a QMessageBox() warning. I am using exec() to keep things
    simple here. When the user clicks on OK the exec() call returns
    and my next step is to call: emit closeEditor(pLineEdit). It is
    here that the core dump occurs. I have no clue as to why. The stacktrace
    is not very clear on what is occurring at this point. I can provide the stacktrace if
    anyone would like to see it.

    I have been looking at this and debugging for several days and still not sure
    why what i am doing is causing such problems. Any feedback, comments or advice
    would be much appreciated.

    QWidget *DeviceObjectItemDelegate::createEditor(
    QWidget *parent,
    const QStyleOptionViewItem & option,
    const QModelIndex & index ) const
    {
    if ( index.column() == S_DEV_OBJ_NAME )
    {
    QLineEdit pEditor = new QLineEdit(parent);
    /
    If the user presses Return or Enter, we take this as confirmation

    • of their edit.
      */
      connect( pEditor, &QLineEdit::returnPressed,
      this, &DeviceObjectItemDelegate::closeAndCommitEditorLE) ;
      return pEditor;
      }
      else
      {
      return QStyledItemDelegate::createEditor( parent, option, index );
      }
      }

    void DeviceObjectItemDelegate::setEditorData(
    QWidget *editor,
    const QModelIndex & index ) const
    {
    else if ( index.column() == S_DEV_OBJ_NAME )
    {
    QString deviceName = index.model()->data(index).toString();
    QLineEdit *pLineEdit = qobject_cast<QLineEdit *>(editor);
    pLineEdit->setText( deviceName);
    }
    else
    {
    QStyledItemDelegate::setEditorData( editor, index );
    }
    }

    void DeviceObjectItemDelegate::setModelData(
    QWidget *editor,
    QAbstractItemModel *model,
    const QModelIndex & index ) const
    {
    if ( index.column() == S_DEV_OBJ_NAME )
    {
    QLineEdit *pLineEdit = qobject_cast<QLineEdit *>(editor);
    printf( "setModelData[%s]\n", pLineEdit->text().toStdString().c_str() );
    model->setData( index, pLineEdit->text() );
    }
    else
    {
    QStyledItemDelegate::setModelData( editor, model, index );
    }
    }

    void DeviceObjectItemDelegate:: closeAndCommitEditorLE()
    {
    QLineEdit pLineEdit = qobject_cast<QLineEdit>(sender() );
    QString Name = pLineEdit->text();
    m_pLineEditor = pLineEdit;

    bool bIsDuplicate = m_pDuplicateDeviceNames->doesNameAlreadyExist(m_deviceType ,
    m_tableType, Name );

    if ( bIsDuplicate)
    {
    /* Name already exists - alert the user */
    issueDuplicateNameWarning( Name );
    / ERROR OCCURS WHEN THE NEXT LINE IS EXECUTED /
    emit closeEditor( pLineEdit);
    emit clearOkToUpdateFlag();
    return;
    }

    setFlag( true );

    emit commitData( pLineEdit);
    emit closeEditor( pLineEdit);
    emit clearOkToUpdateFlag();
    }

    void DeviceObjectItemDelegate:: issueDuplicateNameWarning(
    const QString & Name )
    {
    QMessageBox msgBox;
    msgBox.setIcon(QMessageBox::Warning);
    msgBox.setWindowTitle("Device Type Name - Duplicate" );
    msgBox.setText("Duplicate Device Type Names are NOT allowed!");
    msgBox.setInformativeText(tr("The Device Type Name [%1] is already in use.").arg(Name));
    msgBox.exec();
    }

    mrjjM 1 Reply Last reply
    0
    • S ShawnZ

      Qt5
      I am using an example straight out the book 'Advanced Qt Programming'

      Have a cell in QTableView that when 'double click' generates
      a QLineEdit widget where I override the QStyledItemDelegate::createEditor(),
      setEditorData(), setModelData() functions. Everything is working fine. However,
      the 'core dump' situations arises when the user types in something that is
      not allowed ( i.e. certain text words are reserved ) - So I need to notify
      the user with a QMessageBox() that this text is reserved. I am not sure
      why this is causing the problem:

      Here is the code excerpts to show what I am doing:
      The core dump occurs in the function closeAndCommitEditorLE()
      which is called when the user hits Return in the QLineEdit editor.

      It only occurs after a call to issueDuplicateNameWarning() is called
      which popups a QMessageBox() warning. I am using exec() to keep things
      simple here. When the user clicks on OK the exec() call returns
      and my next step is to call: emit closeEditor(pLineEdit). It is
      here that the core dump occurs. I have no clue as to why. The stacktrace
      is not very clear on what is occurring at this point. I can provide the stacktrace if
      anyone would like to see it.

      I have been looking at this and debugging for several days and still not sure
      why what i am doing is causing such problems. Any feedback, comments or advice
      would be much appreciated.

      QWidget *DeviceObjectItemDelegate::createEditor(
      QWidget *parent,
      const QStyleOptionViewItem & option,
      const QModelIndex & index ) const
      {
      if ( index.column() == S_DEV_OBJ_NAME )
      {
      QLineEdit pEditor = new QLineEdit(parent);
      /
      If the user presses Return or Enter, we take this as confirmation

      • of their edit.
        */
        connect( pEditor, &QLineEdit::returnPressed,
        this, &DeviceObjectItemDelegate::closeAndCommitEditorLE) ;
        return pEditor;
        }
        else
        {
        return QStyledItemDelegate::createEditor( parent, option, index );
        }
        }

      void DeviceObjectItemDelegate::setEditorData(
      QWidget *editor,
      const QModelIndex & index ) const
      {
      else if ( index.column() == S_DEV_OBJ_NAME )
      {
      QString deviceName = index.model()->data(index).toString();
      QLineEdit *pLineEdit = qobject_cast<QLineEdit *>(editor);
      pLineEdit->setText( deviceName);
      }
      else
      {
      QStyledItemDelegate::setEditorData( editor, index );
      }
      }

      void DeviceObjectItemDelegate::setModelData(
      QWidget *editor,
      QAbstractItemModel *model,
      const QModelIndex & index ) const
      {
      if ( index.column() == S_DEV_OBJ_NAME )
      {
      QLineEdit *pLineEdit = qobject_cast<QLineEdit *>(editor);
      printf( "setModelData[%s]\n", pLineEdit->text().toStdString().c_str() );
      model->setData( index, pLineEdit->text() );
      }
      else
      {
      QStyledItemDelegate::setModelData( editor, model, index );
      }
      }

      void DeviceObjectItemDelegate:: closeAndCommitEditorLE()
      {
      QLineEdit pLineEdit = qobject_cast<QLineEdit>(sender() );
      QString Name = pLineEdit->text();
      m_pLineEditor = pLineEdit;

      bool bIsDuplicate = m_pDuplicateDeviceNames->doesNameAlreadyExist(m_deviceType ,
      m_tableType, Name );

      if ( bIsDuplicate)
      {
      /* Name already exists - alert the user */
      issueDuplicateNameWarning( Name );
      / ERROR OCCURS WHEN THE NEXT LINE IS EXECUTED /
      emit closeEditor( pLineEdit);
      emit clearOkToUpdateFlag();
      return;
      }

      setFlag( true );

      emit commitData( pLineEdit);
      emit closeEditor( pLineEdit);
      emit clearOkToUpdateFlag();
      }

      void DeviceObjectItemDelegate:: issueDuplicateNameWarning(
      const QString & Name )
      {
      QMessageBox msgBox;
      msgBox.setIcon(QMessageBox::Warning);
      msgBox.setWindowTitle("Device Type Name - Duplicate" );
      msgBox.setText("Duplicate Device Type Names are NOT allowed!");
      msgBox.setInformativeText(tr("The Device Type Name [%1] is already in use.").arg(Name));
      msgBox.exec();
      }

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @ShawnZ said in Using QTableView/QStyledItemDelegate Issue w/closeAndCommitEditor() coredump:

      I can provide the stacktrace if
      anyone would like to see it.

      Yes please. It might contain more information useful for the hardcores here :)

      1 Reply Last reply
      0
      • O Offline
        O Offline
        Oleksandr Malyushytskyy
        wrote on last edited by
        #3

        If you comment call to issueDuplicateNameWarning, does it still crash?
        if not, do not call it there, you could use timer single shot instead to initiate call to the slot when event loop become idle.

        1 Reply Last reply
        0

        • Login

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