Add QtableView data to the database

1

Hello. How do I add all data from within tableView to the database?

I am adding data in tableView with QStandardItem

//TableView 
count =  ui->tableView->verticalHeader()->count();
verticalHeader.append(QString::number(count + 1));
model.setVerticalHeaderLabels(verticalHeader);

item00 = new QStandardItem(ui->comboBox->currentText());
model.setItem(count, 0, item00);
ui->tableView->setModel(&model);

//insert sqlite
QSqlQuery qry;
qry.prepare("INSERT INTO entrada (entrada_produto) VALUES (?)");
qry.addBindValue(ui->comboBox->currentText());
qry.exec();
    
asked by anonymous 12.04.2014 / 01:06

2 answers

1

Resolved:

    int col = ui->tableView_pedido->verticalHeader()->count();

    for (int i = 0; i < col ; ++i){
        QString pedido = ui->tableView_pedido->model()->data(ui->tableView_pedido->model()->index(i,0)).toString()
    }
    
18.04.2014 / 00:52
2
int col = ui->tableView_pedido->verticalHeader()->count();

QSqlQuery qry;
QString pedido;
qry.prepare("INSERT INTO pedidos (pedido) VALUES (:pedido)");

for (int i = 0; i < col ; i++){
   pedido = ui->tableView_pedido->model()->data(
      ui->tableView_pedido->model()->index(i,0)
   ).toString()
   qry.bindValue(":pedido",pedido); // Creio que pode ser tirado do loop também.
   qry.exec();
}
    
18.04.2014 / 01:26