QtConcurrent, is it worth it?

Simple answer: no.

Although, the description for the framework is very open-ended it's not a separate library. QtConcurrent is a part of a much bigger package called Qt which is a famous GUI framework (that's what drives KDE, for example). Because of this QtConcurrent isn't worth using unless you want to use Qt. It offers some nice functions, though. For example, blockingMap maps items inside a container onto a function. However, functions such as this one are a small part of a big library. It might be worth writing your own simple map function or extract bits of code from QtConcurrent source, remove all the Qt rubbish and base your code on that (quoting the original author, of course). Most of the nice interesting things such as QtFutureWatcher and other concurrency control things that people who use Java are familiar with are not useable unless you delve deeper into Qt. For example, QtFutureWatcher is bound to an instance of QtFuture via a function which accepts special functions that are members of QObject derivatives. It might not sound that bad, what's wrong with including an extra header, learning the interface and making a quick derivative? Not this time. Parts of QObject classes are created using something called MOC (Meta-Object Compiler). It's a Qt thing that generates C++ files for you. You can see how this can get extremely over the top for people who just want nice features of QtConcurrent but don't want to do anything in Qt.

I am going to wrap up with a short bit of code just to illustrate how I used QtConcurrent for a quick test. As you can see I wasn't using Qt containers. It's very neat. But as I said, not worth using. Best way to go is probably learn concurrenct programming API for platform of choice, write a few exercises, then look at QtConcurrent source and come up with a simple, cut-down version. Just so you know, you will need to be comfortable with using templates before you proceed.

  1. int main( int argc, char **argv )
  2. {
  3. boost::filesystem::path path_to_motions( "./motions/" );
  4.  
  5. std::vector<boost::filesystem::path> files;
  6.  
  7. create_file_list( files, path_to_motions );
  8.  
  9. if( files.size() == 0 )
  10. {
  11. std::cout << "No files to process in `" << path_to_motions.string() << "'. Exiting." << std::endl;
  12.  
  13. return 0;
  14. }
  15.  
  16. blockingMap( files, constructGraph );
  17.  
  18. using std::pair;
  19.  
  20. pair<Graph::vertex_iterator, Graph::vertex_iterator> vs = vertices( MotionGraph::getInstance() );
  21.  
  22. blockingMap( vs.first, vs.second, PCA );
  23.  
  24. return 0;
  25. }

P.S. You might jump to conclusions about some of Qt's design decisions. But remember, Qt is a GUI framework and I am writing about using one of its parts for something else. If you read the docs they explain why they don't implement Meta-Objects with templates. Apparently they got good reasons for doing so.