[PyQt] How to close QSqlDatabase connection?
Sibylle Koczian
Sibylle.Koczian at t-online.de
Sun Nov 11 14:38:16 GMT 2007
Hello,
I'm trying to write a very small database application, but I can't get rid of
this error message when I close the main
window: "QSqlDatabasePrivate::removeDatabase:
connection 'qt_sql_default_connection' is still in use, all queries will
cease to work."
At the moment I'm using this code to open and to close the database:
Global function of the module:
def visa_conn():
db = QtSql.QSqlDatabase.addDatabase("QSQLITE")
db.setDatabaseName("/home/sib/pfotweg/visa_s.db")
return db.open()
Method of the main window, connected with a button:
def close(self):
db = QtSql.QSqlDatabase.database()
db.close()
db.removeDatabase(db.connectionNames()[0])
QtGui.QMainWindow.close(self)
And the main() function:
def main(args):
app = QtGui.QApplication(args)
if not visa_conn():
QtGui.QMessageBox.critical(None, ...)
sys.exit(1)
visa_mf = VisaMF()
visa_mf.show()
sys.exit(app.exec_())
I found some posts to this list in the archive with the same error, but no
solution. I've tried to use 'qt_sql_default_connection' as argument to
db.removeDatabase, but that doesn't change anything. What's wrong? Or what
additional info should I give?
Using qt-4.3.1, PyQt4-4.3.1, Python 2.5.1, Gentoo Linux.
Thanks for every hint,
Sibylle
--
Dr. Sibylle Koczian
More information about the PyQt
mailing list