Results 1 to 2 of 2

Thread: QSqlDatabasePrivate - warning

  1. #1
    Join Date
    Jul 2010
    Location
    Poland
    Posts
    184
    Thanks
    70
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default QSqlDatabasePrivate - warning

    Hello!

    I've wrote application with some functions which uses SQL database. I each function I open and read my database like this:

    Qt Code:
    1. QSqlDatabase bdb = QSqlDatabase::addDatabase("QSQLITE");
    2.  
    3. bdb.setDatabaseName("/home/mydatabase.db");
    4. ok = bdb.open();
    5.  
    6. if (ok)
    7. {
    8. out << endl << "OK!" << endl ;
    9. } else {
    10. out << "Error!" << endl;
    11. }
    12.  
    13. QSqlQueryModel *queryModel = new QSqlQueryModel;
    14. queryModel->setQuery("SELECT * FROM some_tab where some_field='something'", bdb);
    15.  
    16. //some code...
    17.  
    18. bdb.close();
    To copy to clipboard, switch view to plain text mode 

    but I get warnings like this in my console:

    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 

    Is it something wrong? Everything works fine, but maybe I should do it in other way?

    thanks in advance
    best regards
    Tomasz

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QSqlDatabasePrivate - warning

    It is complaining because you open/close the default database connection each time one of these chunks of code executes. The first message is probably when you close the connection because your query model and record a still in scope and "using" the connection. The second is when you open a connection overriding the existing default connection.

    Do you really need to recreate the database connection each time or can you open it once and leave the connection open?

Similar Threads

  1. Replies: 0
    Last Post: 14th July 2010, 13:40
  2. Qpainter warning
    By yagabey in forum Qt Programming
    Replies: 1
    Last Post: 16th April 2008, 07:43
  3. warning
    By mickey in forum Newbie
    Replies: 5
    Last Post: 26th September 2006, 23:38
  4. warning
    By mickey in forum General Programming
    Replies: 1
    Last Post: 20th July 2006, 13:22
  5. Replies: 10
    Last Post: 6th March 2006, 16:08

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
  •  
Qt is a trademark of The Qt Company.