Look into QThread, not QtConcurrent.
Look into QThread, not QtConcurrent.
Disclaimer: Although I work on Qt for Nokia, anything I post here is personal
obviously, you need to take care that runQuery() and your class are "thread safe" because they will run concurrently...Qt Code:
#include <boost/bind.hpp> void YourClassName::getProducts(){ QtConcurrent::run( boost::bind(&YourClassName:runQuery, this) ); }To copy to clipboard, switch view to plain text mode
For details on Boost and Boost.Bind see www.boost.org
HTH
cdguenther (4th June 2010)
Thanks for input, but the solution isn't working. It compiles without errors and warnings, program works, but not properly. It doesn't get results from a database. Isn't a new instance of my class being created by QtConcurrent::run( boost::bind(&YourClassName:runQuery, this) );? What can be the couse?
no, boost::bind creates a function object by binding (here runQuery()) a member function to an object (here this). So it exeutes runQuery() on the very object you call getProducs() on.
You can also pass YourClassName() instead of this, then you create a temporary that is used for executing. (Also note that you might need a separe db connection if you are using the db from the main thread, too.)
Bookmarks