[PyQt] Error using QSqlDatabase.removeDatabase()

Sibylle Koczian nulla.epistola at web.de
Sat Feb 15 19:42:23 GMT 2014


Hello,

I don't understand the error I get with the following script:

#!/usr/bin/env python

import sys
from PyQt5 import QtCore
from PyQt5 import QtSql

def checkQSQLITE():
     result = QtSql.QSqlDatabase.isDriverAvailable('QSQLITE')
     print("Treiber verfügbar? {}".format(result))
     db = QtSql.QSqlDatabase.addDatabase("QSQLITE")
     cname = db.connectionName()
     db.setDatabaseName(":memory:")
     result = db.open()
     print("Datenbank geöffnet? {}".format(result))
     if result:
         db.close()
         if db.isOpen():
             print("Datenbank konnte nicht geschlossen werden.")
             print(db.lastError().text())
         else:
             print("Datenbank geschlossen.")
     QtSql.QSqlDatabase.removeDatabase(cname)

def main(args):
     app = QtCore.QCoreApplication(args)
     checkQSQLITE()

if __name__ == "__main__":
     main(sys.argv)


Result:

Treiber verfügbar? True
Datenbank geöffnet? True
Datenbank geschlossen.
QSqlDatabasePrivate::removeDatabase: connection 
'qt_sql_default_connection' is still in use, all queries will cease to work.

Why is the connection still in use after it's been closed? What should I 
do to put it out of use? There is no open query, because no query at all 
has been executed.

This problem isn't new, but I found only questions (my own old one among 
them), no answer, at least not for PyQt.

Thank you for help,
Sibylle


More information about the PyQt mailing list