void MainWindow::removeCustomer() { QSqlTableModel *model = new QSqlTableModel; model->setTable("customers"); model->setEditStrategy(QSqlTableModel::OnManualSubmit); model->select(); QItemSelectionModel *selectionModel = ui.tableView->selectionModel(); QModelIndexList indices = selectionModel->selectedRows(); QModelIndex index; int rowcount = 0; foreach(index, indices) { int row = index.row(); model->removeRows(row, 1, QModelIndex()); qDebug() << "Gonna remove row:" << row << "with index - " << model->data(index); rowcount++; } if (rowcount>0) { if (model->submitAll()) { qDebug() << "Customers db updated successfully!"; } else { qDebug() << "Error updating customers db:" << model->lastError(); } } else { //TODO: Add Warning here "Nothing to delete!" qDebug() << "Nothing to delete!"; } customers();}
C++ (Qt)void MainWindow::removeCustomer() { QModelIndex index; int rowcount = 0; foreach(index, ui.tableView->selectionModel()->selectedRows()) { int row = index.row(); ui.tableView->model()->removeRow(index.row()); qDebug() << "Gonna remove row:" << row << "with index - " << model->data(index); rowcount++; } if (rowcount>0) { if (model->submitAll()) { qDebug() << "Customers db updated successfully!"; } else { qDebug() << "Error updating customers db:" << model->lastError(); } } else { //TODO: Add Warning here "Nothing to delete!" qDebug() << "Nothing to delete!"; } customers();}
C++ (Qt)void MainWindow::removeCustomer() { QModelIndex index; int rowcount = 0; foreach(index, ui.tableView->selectionModel()->selectedRows()) { int row = index.row(); ui.tableView->model()->removeRow(index.row()); qDebug() << "Gonna remove row:" << row << "with index - " << ui.tableView->model()->data(index); rowcount++; } if (rowcount>0) { if (ui.tableView->model()->submitAll()) { qDebug() << "Customers db updated successfully!"; } else { qDebug() << "Error updating customers db:" <<ui.tableView->model()->lastError(); } } else { //TODO: Add Warning here "Nothing to delete!" qDebug() << "Nothing to delete!"; } customers();}