I am using PySide to get Qt bindings in python. The problem I am having is that it cannot find the table name after connecting to the database. First, I have added the database using QSqlDatabase and also setting the name to the sqlite database file. After that I created a QSqlTableModel and set the table to be one of the tables inside my database. When I do that, nothing shows up. By calling the lastError() function it says that the table was not found. I know the connection to the database is good because db.open() returns true. I manually looked into the database file and there are indeed tables with that specific name in it. One thing that I find interesting is that the pointer to the database is different between the QSqlDatabase and the QSqlTableMode(). Is this supposed to happen? The pointers are different but the name are (The ones that says drivers = ..., database =...., etc)
What could be the issue? Here is how I am setting it up.
db = QSqlDatabase.addDatabase("QSQLITE")
db.setDatabaseName("test.db")
print str(db.open())
print str(db.database())
model = QSqlTableModel()
model.setTable("AntennaModels")
model.select()
print str(model.lastError())
Here is what prints out when I use db.database() and model.database()
<PySide.QtSql.QSqlDatabase(driver=""QSQLITE"", database=""test.db"", host="""", port=-1, user="""", open=true) at 0x104bf73b0>
<PySide.QtSql.QSqlDatabase(driver=""QSQLITE"", database=""test.db"", host="""", port=-1, user="""", open=true) at 0x104bf73f8>
Aucun commentaire:
Enregistrer un commentaire