Hi,

I am struggling with the multi-thread QSQLITE, the GUI thread is refresh the display through QSqlTableModel, the other thread insert data to sqlite cyclically.
but the problem is, once GUI thread use QSqlTableModel::select(), the other thread could not insert , and return : QSqlError("5", "Unable to fetch row", "database is locked")

what could I do next step to resolve the problem?

my codes like below:

this is the GUI thread
Qt Code:
  1. processDisplayDB =new QSqlDatabase(QSqlDatabase::addDatabase("QSQLITE","processDisplaydb"));
  2. processDisplayDB->setDatabaseName("databases/ProductionData.s3db");
  3. if(!processDisplayDB->open()){
  4. qDebug()<<"Could not open file!"<<endl;
  5. return;
  6. }else{
  7. qDebug()<<"Open file: "<<processDisplayDB->databaseName()<<" sucessfully!"<<endl;
  8. }
  9. modelProcessDisplay = new QSqlTableModel(ui->tableViewProcessDisplay,*processDisplayDB);
  10. modelProcessDisplay->setTable("processtable");
To copy to clipboard, switch view to plain text mode 

and through a timer to refresh the display
Qt Code:
  1. connect(&cylicTimerProcessDisplay,&QTimer::timeout,this,&MainWindow::processDisplayUpdate_cylic);
To copy to clipboard, switch view to plain text mode 
Qt Code:
  1. void MainWindow::processDisplayUpdate_cylic()
  2. {
  3. modelProcessDisplay->select();
  4. }
To copy to clipboard, switch view to plain text mode 

the other thread is like this
Qt Code:
  1. processDB = new QSqlDatabase(QSqlDatabase::addDatabase("QSQLITE","processDB"));
  2. processDB->setDatabaseName("databases/ProductionData.s3db");
  3. if(!processDB->open()){
  4. qDebug()<<"Could not open file!"<<endl;
  5. return;
  6. }else{
  7. qDebug()<<"Open file: "<<processDB->databaseName()<<" sucessfully!"<<endl;
  8. }
To copy to clipboard, switch view to plain text mode 
and write data cyclic
Qt Code:
  1. QSqlQuery query(*processDB);
  2. qDebug()<<"insert processtable prepare : "
  3. <<query.prepare("INSERT INTO processtable(SerialNo) "
  4. "VALUES(:SerialNo)");
  5. query.bindValue(":SerialNo",currentSerialNo);
  6. qDebug()<<"insert processtable: "<<query.exec();
To copy to clipboard, switch view to plain text mode 

but the query.exec() return false, once the GUI thread excuted the select(), the return error is : QSqlError("5", "Unable to fetch row", "database is locked")