I'm having trouble connecting an existing database to an instance of QSqlDatabase. Is it possible to do this?
I've read through a good amount of posts related to this issue; most of them imply that it's at least possible to do this. However, I haven't been able to do it. It seems like a pretty straightforward process as well.
db = QSqlDatabase.addDatabase("QSQLITE")
db.setDatabaseName("moves.sqlite") # this is the name of the database. It's on the same line directory as this code
# db.setDatabaseName(os.path.abspath("./moves.sqlite"))
opened = db.open()
if not opened:
print("database not found!")
return
I end up getting the print message "database not found!". I should be able to get the database opened and perform queries on it. Have I got the QSqlDatabase class completely wrong?
Edit: At the request of @musicmante in the comments below, I added these lines:
print(db.lastError().databaseText())
print(db.lastError().driverText())
For both, the output was "driver not loaded. I went ahead and added:
print(QSqlDatabase.drivers())
This got me an empty list.