Results 1 to 4 of 4

Thread: removing database

  1. #1
    Join Date
    Jan 2011
    Posts
    32
    Thanks
    11
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default removing database

    What is wrong with this code. Why I get warning about it?
    WARNING: QSqlDatabasePrivate::removeDatabase: connection 'qt_sql_default_connection' is still in use, all queries will cease to work.

    Qt Code:
    1. {
    2. QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
    3. db.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb)};FIL={MSAccess};DBQ=E:file.name" );
    4. qDebug() << "DRIVERS :" << QSqlDatabase::drivers();
    5.  
    6. if (!db.open()) {
    7. qDebug()<< db.lastError().text();
    8. return false;
    9. }
    10. }
    11.  
    12. if(QSqlDatabase::database().isOpen()) {
    13. qDebug() << "db name :" << QSqlDatabase::database().connectionName();
    14. QSqlDatabase::database().close();
    15. QSqlDatabase::removeDatabase(QSqlDatabase::database().connectionName());
    16. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2011
    Posts
    32
    Thanks
    11
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: removing database

    Should I leave this warning as it is?
    Because I need to close connection and open new one to another database.

  3. #3
    Join Date
    Aug 2008
    Posts
    45
    Thanks
    1
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: removing database

    Do you have any QSqlQuery objects alive when you try to remove the connection? If you have, then that would cause the warning.

  4. #4
    Join Date
    Apr 2011
    Posts
    124
    Thanks
    1
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows Symbian S60

    Default Re: removing database

    Yep, you probably have a QSqlQuery object that hasn't passed out of scope and hasn't been clear()ed.

Similar Threads

  1. [SOLVED] database opened .. database not open
    By kapitanluffy in forum Qt Programming
    Replies: 1
    Last Post: 27th February 2011, 10:39
  2. Removing database connections
    By Matt31415 in forum Qt Programming
    Replies: 1
    Last Post: 4th July 2010, 07:08
  3. Crash on removing a row
    By inktomi in forum Qt Programming
    Replies: 10
    Last Post: 17th June 2010, 12:59
  4. Replies: 9
    Last Post: 20th May 2010, 09:55
  5. Removing a directory entirely
    By Barry79 in forum Qt Programming
    Replies: 0
    Last Post: 11th May 2009, 15:09

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.