Solved QSqlTableModel not work
-
Hi!
I connected to SQLite{ ui->setupUi(this); myDatabase = QSqlDatabase::addDatabase("QSQLITE"); myDatabase.setDatabaseName("./sample.db"); if (myDatabase.open()) {qDebug()<<"db is opened";} else {qDebug()<<"db not opened";} }
And I'm trying to make a model:
QSqlTableModel *tableModel = new QSqlTableModel(this); tableModel ->setTable("test"); tableModel->select(); qDebug()<<tableModel->lastError();
But I get error:
QSqlError("", "Unable to find table test", "")
But I have this table in my database for sure
-
But I have this table in my database for sure
Well I doubt that "QSqlTableModel not work".
Why don't you try seeing what tables it sees via: https://doc.qt.io/qt-5/qsqldatabase.html#tables
-
One other possible problem is that the default db is not
sample.db
. try passing the db to theQSqlTableModel
explicitly -
@Mikeeeeee Is the .db in the build folder where the executable is?
-
Magically, in the morning, everything worked itself out. Sorry for bother.