I am calling a method from another class after inserting data. But this is returning an SQLite error:
QSqlDatabasePrivate::removeDatabase: connection 'qt_sql_default_connection' is still in use, all queries will cease to work.
QSqlDatabasePrivate::addDatabase: duplicate connection name 'qt_sql_default_connection', old connection removed.
Code:
example_insert.cpp
void DialogVenda::inserte_venda(){
//QSqlQuery etc....
if (qry.lastInsertId()>0){
QMessageBox::information(this,"Cadastro de pedido", "Pedido cadastrado com sucesso.");
MainPrincipal *pt= new MainPrincipal(this);
pt->tableView_listaVendas();
}
}
MainPrincipal.cpp
MainPrincipal::MainPrincipal(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainPrincipal){
ui->setupUi(this);
base = new connection(NAME_BASE);
if(!base->openBD()){
QMessageBox::critical(this, "Erro", ERRO_BASE);
return;
}
}
void MainPrincipal::tableView_listaVendas(){
model = new QSqlQueryModel;
model->setQuery("SELEC * FROM empresa_estoqueSaida WHERE strftime('%Y-%m-%d', saida_dataCadastro)='"+dateTime.toString("yyyy-MM-dd")+"'");
model->setHeaderData(0, Qt::Horizontal, tr("Cliente"));
model->setHeaderData(1, Qt::Horizontal, tr("Endereço"));
model->setHeaderData(2, Qt::Horizontal, tr("Valor"));
model->setHeaderData(3, Qt::Horizontal, tr("Pagamento"));
model->setHeaderData(6, Qt::Horizontal, tr("Data"));
ui->tableView_vendas->setModel(model);
}
The goal is to update tableView_vendas
after inserting the sale.