O
O
Oleg Seledets2018-07-01 18:27:23
Qt
Oleg Seledets, 2018-07-01 18:27:23

Why ASSERT: "!isEmpty()"?

when a row is selected in the tableview, the code works, the deletion occurs.
and when selecting one cell, it throws an error:
ASSERT: "!isEmpty()" in file C:/Qt/5.8/mingw53_32/include/QtCore/qlist.h, line 344
this line:

inline T& first() { Q_ASSERT(!isEmpty()); return *begin(); }

the code of the section where the selection check is:
QSqlQueryModel *setquery1 = new QSqlQueryModel;
    QSqlTableModel *model = new QSqlTableModel;
    QItemSelectionModel *selectModel = ui->tableView->selectionModel();
    if (selectModel->hasSelection())
    {
       int nr = selectModel->selectedRows().first().row();
       ui->dir_excel->setText(ui->tableView->model()->data(ui->tableView->model()->index(nr,0)).toString());
       if (QMessageBox::Yes == QMessageBox::question(this, "Удалить?",
                             "Уверены?",
                             QMessageBox::Yes|QMessageBox::No))
       {
            ui->dir_excel->setText(ui->tableView->model()->data(ui->tableView->model()->index(nr,0)).toString());
            QString indid = ui->tableView->model()->data(ui->tableView->model()->index(nr,0)).toString();
            setquery1->setQuery("DELETE FROM ships WHERE id="+indid+";");
            model->setTable("ships");
            model->select();
            ui->tableView->setModel(model);
}
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ighor July, 2018-07-01
@oleja1ee7

And output selectModel->selectedRows().count() what is there?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question