I have a delete button (QPushButton) in the last column of each row of my table view. I create these buttons and directly configure them. Since I allocate memory dynamically, I want to free this memory, but I did not store pointers to these buttons anywhere, so I try to get the widget while cleaning and deleting them.
SDelegate* myDelegate;
myDelegate = new SDelegate();
STableModel* model = new STableModel(1, 7, this);
myWindow->tableView->setModel(model);
myWindow->tableView->setItemDelegate(myDelegate);
for(int i = 0; i < no_of_rows; ++i) {
QPushButton* deleteButton = new QPushButton();
myWindow->tableView->setIndexWidget(model->index(i, 6), deleteButton);
}
exec();
for(int i = 0; i < no_of_rows; ++i) {
QWidget* widget = myWindow->tableView->indexWidget(model->index(i, 6));
if (widget)
delete widget;
}
delete model;
delete myDelegate;
I get a failure in qt5cored.dll (unhandled exception) and the application crashes in qcoreapplication.h with the following code:
inline bool QCoreApplication::sendEvent(QObject *receiver, QEvent *event)
{ if (event) event->spont = false; return self ? self->notifyInternal(receiver, event) : false; }
During debugging, there is no problem removing these widgets, but after that the code crashes at some other point. I am using QTableView and a custom class for a model that has inherited QAbstractTableModel.
wazza source
share