Results 1 to 2 of 2

Thread: Using QTableView & QSytledItemDelegate - Issue w/ closeAndCommitEditorLE() :core dump

  1. #1
    Join Date
    Jun 2008
    Posts
    5
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Using QTableView & QSytledItemDelegate - Issue w/ closeAndCommitEditorLE() :core dump

    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();
    }

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,199
    Thanks
    237
    Thanked 668 Times in 658 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Using QTableView & QSytledItemDelegate - Issue w/ closeAndCommitEditorLE() :core

    I don't see anything significantly different from your code and Summerfield's, except for your failures to check if the QLineEdit pointer returned from qobject_cast is non-null. Sure, it *shouldn't* ever be null but what happens if it is?

    My guess is that something in the code that you haven't posted is causing some stack corruption, and the error just happens to manifest itself when you get to that part of the code.

    Please use CODE tags when posting source code - see my signature block for how to do that.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. generate core dump in windows application
    By deepal_de in forum Qt Programming
    Replies: 1
    Last Post: 29th November 2011, 14:34
  2. generate core dump
    By jaxrpc in forum Newbie
    Replies: 2
    Last Post: 11th June 2010, 11:09
  3. core dump qdevelop
    By jaxrpc in forum Newbie
    Replies: 0
    Last Post: 9th June 2010, 05:16
  4. QGraphicsScene core dump?
    By cookie1909 in forum Newbie
    Replies: 2
    Last Post: 25th April 2009, 08:06
  5. core dump
    By DadaLee in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 16th September 2008, 11:05

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.