thefatladysingsopera
8th September 2011, 08:34
I have a QTableView and i am using this code to insert new data.
void smith::on_newButton_clicked()
{
ui.fEdit->clear();
ui.lnEdit->clear();
ui.cEdit->clear();
ui.cityEdit->clear();
ui.newButton->setEnabled(false);
ui.saveEdits->show();
ui.saveNew->show();
ui.cancelButton->show();
ui.nextButton->setEnabled(false);
ui.previousButton->setEnabled(false);
ui.deleteButton->setEnabled(false);
}
The function clears the forms and takes in new data and upon a click on the save button,the input is passed to saveNew function:
void smith::saveNew()
{
//insert code above...
query.bindValue(":firstname", ui.fEdit->text());
query.bindValue(":lastname", ui.lnEdit->text());
query.bindValue(":country", ui.cEdit->text());
query.bindValue(":city", ui.cityEdit->text());
int das = query.lastInsertId().toInt();
query.exec();
tableModel->submitAll();
int row = tableModel->rowCount();
tableModel->insertRow(row);
QModelIndex index = tableModel->index(das, firstname);
ui.tableView->setCurrentIndex(index);
ui.tableView->edit(index);
ui.newButton->setEnabled(true);
ui.saveNew->setEnabled(true);
ui.saveEdits->setEnabled(true);
ui.nextButton->setEnabled(true);
ui.previousButton->setEnabled(true);
ui.cancelButton->setEnabled(true);
ui.deleteButton->setEnabled(true);
}
When i click i enter data and click input it works as expected(a new row is inserted,data is inserted to sqlite and the newly created data is presented for editing.However,when i click new button again and click save,no new row is inserted and the lastinsertedrecord shows what i inserted the immediate previous time and not the most new insert but still data is still inserted to sqlite.
What could be the problem?.
void smith::on_newButton_clicked()
{
ui.fEdit->clear();
ui.lnEdit->clear();
ui.cEdit->clear();
ui.cityEdit->clear();
ui.newButton->setEnabled(false);
ui.saveEdits->show();
ui.saveNew->show();
ui.cancelButton->show();
ui.nextButton->setEnabled(false);
ui.previousButton->setEnabled(false);
ui.deleteButton->setEnabled(false);
}
The function clears the forms and takes in new data and upon a click on the save button,the input is passed to saveNew function:
void smith::saveNew()
{
//insert code above...
query.bindValue(":firstname", ui.fEdit->text());
query.bindValue(":lastname", ui.lnEdit->text());
query.bindValue(":country", ui.cEdit->text());
query.bindValue(":city", ui.cityEdit->text());
int das = query.lastInsertId().toInt();
query.exec();
tableModel->submitAll();
int row = tableModel->rowCount();
tableModel->insertRow(row);
QModelIndex index = tableModel->index(das, firstname);
ui.tableView->setCurrentIndex(index);
ui.tableView->edit(index);
ui.newButton->setEnabled(true);
ui.saveNew->setEnabled(true);
ui.saveEdits->setEnabled(true);
ui.nextButton->setEnabled(true);
ui.previousButton->setEnabled(true);
ui.cancelButton->setEnabled(true);
ui.deleteButton->setEnabled(true);
}
When i click i enter data and click input it works as expected(a new row is inserted,data is inserted to sqlite and the newly created data is presented for editing.However,when i click new button again and click save,no new row is inserted and the lastinsertedrecord shows what i inserted the immediate previous time and not the most new insert but still data is still inserted to sqlite.
What could be the problem?.