samedi 29 août 2015

Calling a method in another class

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){

        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);
    }

Aucun commentaire:

Enregistrer un commentaire