There are several mistakes in your code. Also, here are some tips'n'tricks for your situation:
- Are you sure that your
model
member was initialized/instantiated? To check it just doif model!=NULL
check. - Are you sure that your
db
(inPersistenceAdapter::loadServerList()
) was instantiated? _To check it just doif model!=NULL
check. Also, check if that db was successfully opened, and check if itisOpen
at moment of use. Keep in mind that you can got some errors while doing multithreaded database access. - I do not recommend create
QSqlQuery
, instead you can use anothersetQuery
method. - After you apply your query, do check:
if (model.lastError().isValid()) qDebug() << model.lastError();
- Check order of calling your functions -- if instantiating
db
goes earlier than accessingdb
and so on.
Hope this tips will throw light upon. Good luck!