Results 1 to 3 of 3

Thread: How to realize multi-threaded database query?

  1. #1
    Join Date
    Aug 2008
    Posts
    33
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question How to realize multi-threaded database query?

    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);
    //...

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to realize multi-threaded database query?

    look at this article Asynchronous Database Access with Qt 4.x
    PS. please, use tags CODE.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Aug 2008
    Posts
    33
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to realize multi-threaded database query?

    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.

Similar Threads

  1. Multiple database connections
    By cyberboy in forum Qt Programming
    Replies: 3
    Last Post: 30th March 2008, 16:56

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.