Results 1 to 3 of 3

Thread: App crash when using context menu for change model

  1. #1
    Join Date
    Oct 2012
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default App crash when using context menu for change model

    Hi,
    I need to change model using context menu of QTreeView. The problem occurs when is closed the context menu, that requested paint event QTreeView, and during drawing is call model->update(), which resets the model and it causes the app crash.

    valgrind:
    Qt Code:
    1. ==8920== Invalid read of size 8
    2. ==8920== at 0x4380D3: GerberNode::parent() (gerbernode.cpp:59)
    3. ==8920== by 0x447F0C: PropertyModel::parent(QModelIndex const&) const (propertymodel.cpp:422)
    4. ==8920== by 0x5A914AB: QProxyModel::parent(QModelIndex const&) const (in /usr/lib/libQtGui.so.4.8.3)
    5. ==8920== by 0x4495BA: PropertyProxy::parent(QModelIndex const&) const (propertyproxy.cpp:58)
    6. ==8920== by 0x5A53191: QTreeView::drawRow(QPainter*, QStyleOptionViewItem const&, QModelIndex const&) const (in /usr/lib/libQtGui.so.4.8.3)
    7. ==8920== by 0x5A572EE: QTreeView::drawTree(QPainter*, QRegion const&) const (in /usr/lib/libQtGui.so.4.8.3)
    8. ==8920== by 0x5A57AFB: QTreeView::paintEvent(QPaintEvent*) (in /usr/lib/libQtGui.so.4.8.3)
    9. ==8920== by 0x555D7A1: QWidget::event(QEvent*) (in /usr/lib/libQtGui.so.4.8.3)
    10. ==8920== by 0x5908425: QFrame::event(QEvent*) (in /usr/lib/libQtGui.so.4.8.3)
    11. ==8920== by 0x5A13A4A: QAbstractItemView::viewportEvent(QEvent*) (in /usr/lib/libQtGui.so.4.8.3)
    12. ==8920== by 0x5A58210: QTreeView::viewportEvent(QEvent*) (in /usr/lib/libQtGui.so.4.8.3)
    13. ==8920== by 0x615E755: QCoreApplicationPrivate::sendThroughObjectEventFilters(QObject*, QEvent*) (in /usr/lib/libQtCore.so.4.8.3)
    14. ==8920== Address 0x15a3cd80 is 16 bytes inside a block of size 24 free'd
    15. ==8920== at 0x4C2A86C: operator delete(void*) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
    16. ==8920== by 0x4393E3: void qDeleteAll<QList<GerberNode*>::const_iterator>(QList<GerberNode*>::const_iterator, QList<GerberNode*>::const_iterator) (qalgorithms.h:322)
    17. ==8920== by 0x438D37: void qDeleteAll<QList<GerberNode*> >(QList<GerberNode*> const&) (qalgorithms.h:330)
    18. ==8920== by 0x4385C7: GerberNode::clear() (gerbernode.cpp:109)
    19. ==8920== by 0x438541: GerberNode::clear() (gerbernode.cpp:107)
    20. ==8920== by 0x444C71: PropertyModelPrivate::updateModel() (propertymodel.cpp:46)
    21. ==8920== by 0x44681B: PropertyModel::update() (propertymodel.cpp:251)
    22. ==8920== by 0x41829D: MainWindow::on_treeProperty_customContextMenuRequested(QPoint const&) (mainwindow.cpp:433)
    23. ==8920== by 0x44D401: MainWindow::qt_static_metacall(QObject*, QMetaObject::Call, int, void**) (moc_mainwindow.cpp:96)
    24. ==8920== by 0x44D5A7: MainWindow::qt_metacall(QMetaObject::Call, int, void**) (moc_mainwindow.cpp:144)
    25. ==8920== by 0x6173C92: QMetaObject::activate(QObject*, QMetaObject const*, int, void**) (in /usr/lib/libQtCore.so.4.8.3)
    26. ==8920== by 0x5550921: QWidget::customContextMenuRequested(QPoint const&) (in /usr/lib/libQtGui.so.4.8.3)
    27. ==8920==
    To copy to clipboard, switch view to plain text mode 

    mainwindow.cpp
    Qt Code:
    1. void MainWindow::on_treeProperty_customContextMenuRequested(const QPoint &aPos)
    2. {
    3. if (iEditStatus->getIndex().isValid()) {
    4. QModelIndex index = iEditStatus->getIndex();
    5. QModelIndex indexModel = iModelGerber->index(index.row(), index.column(), index.parent());
    6. GerbDCode dcode = qVariantValue<GerbDCode>(index.data(Qt::EditRole));
    7.  
    8. QAction * action = iMenuModifier->exec(ui->treeProperty->mapToGlobal(aPos));
    9.  
    10. if (action == ui->actionAddModifier) {
    11. double value = dcode.param.at(0).toDouble()/4;
    12. dcode.param.append(value);
    13. iModelGerber->setData(indexModel, QVariant(QMetaType::type("GerbDCode"), &dcode), GerbFormat::ROLE_UNDO);
    14. iModelProperty->update();
    15. ui->treeProperty->expandAll();
    16. }
    17. else if (action == ui->actionRemoveModifier) {
    18. dcode.param.removeLast();
    19. iModelGerber->setData(indexModel, QVariant(QMetaType::type("GerbDCode"), &dcode), GerbFormat::ROLE_UNDO);
    20. iModelProperty->update(); //PropertyModel class
    21. ui->treeProperty->expandAll();
    22. }
    23. }
    24. }
    To copy to clipboard, switch view to plain text mode 

    propertymodel.cpp
    Qt Code:
    1. void PropertyModel::update()
    2. {
    3. Q_D(PropertyModel);
    4. beginResetModel();
    5. d->updateModel();
    6. endResetModel();
    7. }
    To copy to clipboard, switch view to plain text mode 

    Any help is appreciated.

  2. #2
    Join Date
    Feb 2011
    Location
    Bangalore
    Posts
    207
    Thanks
    20
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: App crash when using context menu for change model

    It is tough to tell exactly from the code, but looks like the Gerber::Node:arent() is crashing. Go through the function as to why it is not able to reset. You can verify your model from ModelTest which qt provides. Often for complicated tree models, it is good to have.

  3. #3
    Join Date
    Oct 2012
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: App crash when using context menu for change model

    Thanks for response. I finally solved the problem by replacing the update() as methods removeRow() and insertRow().

Similar Threads

  1. Replies: 1
    Last Post: 4th November 2011, 11:25
  2. Context menu on tab
    By wolfi3b in forum Newbie
    Replies: 2
    Last Post: 18th October 2010, 17:35
  3. Context menu
    By dejvis in forum Newbie
    Replies: 2
    Last Post: 20th September 2009, 22:02
  4. Crash during OpenGL context creation
    By PaladinOfKaos in forum Qt Programming
    Replies: 1
    Last Post: 13th May 2009, 07:39
  5. Qwt and context menu
    By giusepped in forum Qwt
    Replies: 1
    Last Post: 9th December 2008, 08:55

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.