PDA

View Full Version : Calling a method in another class; erro Sqlite.



Soft
29th August 2015, 22:57
Hello, I am calling a method in another class, after the insertion of data. But this returning an error SQLite :


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.

Source:

insert_sales.cpp


void DialogSales::insert_sale(){
//QSqlQuery
if (qry.lastInsertId()>0){
QMessageBox::information(this,"Register", "Registered successfully.");
MainSystem *ms= new MainSystem(this);
ms->tableView_listSales();
}
}

MainSystem.cpp


MainSystem::MainSystem(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainSystem){
ui->setupUi(this);
base = new connection(NAME_BASE);
if(!base->openBD()){
QMessageBox::critical(this, "Erro", ERRO_BASE);
return;
}
}

void MainSystem::tableView_listSales(){
model = new QSqlQueryModel;
model->setQuery("SELEC * FROM inventory WHERE strftime('%Y-%m-%d', inventory_date)='"+dateTime.toString("yyyy-MM-dd")+"'");
model->setHeaderData(0, Qt::Horizontal, tr("Client"));
model->setHeaderData(1, Qt::Horizontal, tr("Address"));
model->setHeaderData(3, Qt::Horizontal, tr("Payment"));
model->setHeaderData(6, Qt::Horizontal, tr("Date"));
ui->tableView_sales->setModel(model);
}

anda_skoa
30th August 2015, 08:38
Where do you call the methods that log the errors?

Cheers,
_

Soft
30th August 2015, 12:15
Where do you call the methods that log the errors?

Cheers,
_

Here after Call:


MainSystem *ms= new MainSystem(this);
ms->tableView_listSales();

I think , that the problem is a connection:



#define controller "QSQLITE"

bool connection::openBD()
{

if(!QSqlDatabase::isDriverAvailable(controller)){
return false;
}
base = QSqlDatabase::addDatabase(controller);
base.setDatabaseName(m_name);
return base.open();
}

anda_skoa
30th August 2015, 12:29
Here after Call:


MainSystem *ms= new MainSystem(this);
ms->tableView_listSales();

You forgot to post the "after" code :-)



I think , that the problem is a connection:

Maybe you are accidentally calling it more than once?

Cheers,
_

Soft
30th August 2015, 13:07
You forgot to post the "after" code :-)


Maybe you are accidentally calling it more than once?

Cheers,
_

I think so .