Results 1 to 5 of 5

Thread: Calling a method in another class; erro Sqlite.

  1. #1
    Join Date
    Aug 2015
    Posts
    3

    Lightbulb Calling a method in another class; erro Sqlite.

    Hello, I am calling a method in another class, after the insertion of data. But this returning an error SQLite :

    Qt Code:
    1. QSqlDatabasePrivate::removeDatabase: connection 'qt_sql_default_connection' is still in use, all queries will cease to work.
    2. QSqlDatabasePrivate::addDatabase: duplicate connection name 'qt_sql_default_connection', old connection removed.
    To copy to clipboard, switch view to plain text mode 

    Source:

    insert_sales.cpp
    Qt Code:
    1. void DialogSales::insert_sale(){
    2. //QSqlQuery
    3. if (qry.lastInsertId()>0){
    4. QMessageBox::information(this,"Register", "Registered successfully.");
    5. MainSystem *ms= new MainSystem(this);
    6. ms->tableView_listSales();
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 

    MainSystem.cpp

    Qt Code:
    1. MainSystem::MainSystem(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainSystem){
    2. ui->setupUi(this);
    3. base = new connection(NAME_BASE);
    4. if(!base->openBD()){
    5. QMessageBox::critical(this, "Erro", ERRO_BASE);
    6. return;
    7. }
    8. }
    9.  
    10. void MainSystem::tableView_listSales(){
    11. model = new QSqlQueryModel;
    12. model->setQuery("SELEC * FROM inventory WHERE strftime('%Y-%m-%d', inventory_date)='"+dateTime.toString("yyyy-MM-dd")+"'");
    13. model->setHeaderData(0, Qt::Horizontal, tr("Client"));
    14. model->setHeaderData(1, Qt::Horizontal, tr("Address"));
    15. model->setHeaderData(3, Qt::Horizontal, tr("Payment"));
    16. model->setHeaderData(6, Qt::Horizontal, tr("Date"));
    17. ui->tableView_sales->setModel(model);
    18. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Calling a method in another class; erro Sqlite.

    Where do you call the methods that log the errors?

    Cheers,
    _

  3. #3
    Join Date
    Aug 2015
    Posts
    3

    Default Re: Calling a method in another class; erro Sqlite.

    Quote Originally Posted by anda_skoa View Post
    Where do you call the methods that log the errors?

    Cheers,
    _
    Here after Call:

    Qt Code:
    1. MainSystem *ms= new MainSystem(this);
    2. ms->tableView_listSales();
    To copy to clipboard, switch view to plain text mode 

    I think , that the problem is a connection:


    Qt Code:
    1. #define controller "QSQLITE"
    2.  
    3. bool connection::openBD()
    4. {
    5.  
    6. if(!QSqlDatabase::isDriverAvailable(controller)){
    7. return false;
    8. }
    9. base = QSqlDatabase::addDatabase(controller);
    10. base.setDatabaseName(m_name);
    11. return base.open();
    12. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Calling a method in another class; erro Sqlite.

    Quote Originally Posted by Soft View Post
    Here after Call:

    Qt Code:
    1. MainSystem *ms= new MainSystem(this);
    2. ms->tableView_listSales();
    To copy to clipboard, switch view to plain text mode 
    You forgot to post the "after" code :-)

    Quote Originally Posted by Soft View Post
    I think , that the problem is a connection:
    Maybe you are accidentally calling it more than once?

    Cheers,
    _

  5. #5
    Join Date
    Aug 2015
    Posts
    3

    Default Re: Calling a method in another class; erro Sqlite.

    Quote Originally Posted by anda_skoa View Post
    You forgot to post the "after" code :-)


    Maybe you are accidentally calling it more than once?

    Cheers,
    _
    I think so .

Similar Threads

  1. Calling a method from a non-member method
    By AndresBarbaRoja in forum Newbie
    Replies: 5
    Last Post: 19th March 2011, 10:38
  2. Replies: 7
    Last Post: 2nd September 2010, 19:42
  3. error calling method using connect
    By jeffmetal in forum Newbie
    Replies: 4
    Last Post: 22nd April 2010, 18:09
  4. Replies: 1
    Last Post: 30th March 2009, 16:07
  5. Replies: 3
    Last Post: 16th May 2007, 11:07

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.