QSqlQuery issue
-
Hi and welcome to devnet,
very hard to help without the code.
BTW, the debug info says that the error is insideWritingData::updateNodeStatus
-
Thanks for your reply, here the funtion
WritingData::updateNodeStatus
bool WritingData::updateNodeStatus(QString node_Id , int node_status) { bool submit=false; if(writingDb.isOpen()) { QSqlTableModel model(NULL, writingDb); model.setTable("nodes"); model.setFilter(QString("node_id = '%1'").arg(node_Id)); model.select(); if (model.rowCount() == 1) { QSqlRecord record = model.record(0); record.setValue("node_id", node_Id); record.setValue("node_status_id", QString::number(node_status)); model.setRecord(0, record); submit=model.submitAll(); } } return submit; }
This function is called by another thread for updating the last pool column of a specified node (filtered by its id). Moreover, this function uses a writing connexion (called here "writingDb").
-
Hi,
the error happens in the QSqlModel destructor. (you should run in debug mode to try to understand why it crashes)
QUESTION: are you sure your code does what you want? each time you overwrite the first record without storing all data
model.setRecord(0, record)
-
@mcosta
Hi,I have tried to use another method to update the database. Here the implementation of the new function: (this function updates the status of one node (network node), that's why i overwrite each time the first record)
bool WritingData::updateNodeStatus(QString node_Id , int node_status) { bool submit=false; if(writingDb.isOpen()) { QSqlQuery query(writingDb); submit=query.exec(QString("UPDATE nodes set node_status_id='%1' where node_id='%2'").arg(QString::number(node_status)).arg(node_Id)); } return submit; }
There still the same problem. I think the problem is caused by the function
QListData::remove(int)Note : I have this problem only on Linux Os (ubuntu 14.04). It doesn't crash on windows OS.
Have you any idea?
Edited: Please use ``` (3 back-ticks) for code blocks - p3c0
-
-
Hi,
I read in the offical documentation this phrase : The driver is locked for updates while a select is executed. This may cause problems when using QSqlTableModel because Qt's item views fetch data as needed (with QSqlQuery::fetchMore() in the case of QSqlTableModel).
In fact, i tested my application by disabling the reading component (thread) and i haven't any problem. That's why, i think that i have this problem.
There is any way to solve this problem?
-
Hi,
the solution is to use the connection only inside the GUI thread. Or, if you need to work with multiple threads, you have to use more connections.
-
I'm already using two connections (readingDB and writingDB) and each connection has a specific name.
-
mmmm,
the problem is that SQLite (the DB not the Qt driver) cannot handle multiple connections in the right way (is a file access problem).
DO you need to open the database in ReadWrite mode in both threads (do you need to modify through the view)??
If the view is read-only you can try to specifyQSQLITE_OPEN_READONLY
for the UI thread connection -
Thanks for your reply,
I have already tried this solution, but unfortantly, it doesn't resolve the problem (after a few minutes, the application crashes on Linux).