PDA

View Full Version : How to realize multi-threaded database query?



bangqianchen
12th November 2008, 15:05
I means that one thread query the database ,other UI thread retrive the records and show in the window.
I use QSqlQueryModel object set the query, a QTableView object show the records,after finish query, call the QTableView's setModel function, the result show correctly.
however ,if the query take too much time,the user can not wait for such a long time.
the fellowing is part of my code

m_pQryModel = new QSqlQueryModel;
m_pTblView = new QTableView(this);
//someother codes
QString szSQL=tr("SELECT XXX ......");
m_pQryModel->setQuery(szSQL);
if(m_pQryModel->lastError().isValid())
{
AlarmBox(m_pQryModel->lastError().text().toAscii().data());
return false;
}
m_pTblView->setModel(m_pQryModel);
//...

spirit
12th November 2008, 15:18
look at this article Asynchronous Database Access with Qt 4.x (http://www.linuxjournal.com/article/9602)
PS. please, use tags CODE.

bangqianchen
14th November 2008, 07:15
I have read this paper,however,the auther is focus on exec batch of SQL,My Question is, if one SQL is Time-consuming,such as SELECT ... FROM tbl_1 JOIN ON ... WHERE ...,I want one work thread execute this SQL, Another UI thread can retrive part of records from the work thread. and show in the window.