QtConcurrent in Qt 4.4

Finally decided to try out the fancy QtConcurrent! To be honest, description sounds so intriguing.

And now a bit of day-to-day "Error include file not found" crap all of us get when we see some code bigger than 2 files for the first time in our lives.

No, it doesn't work without Qt. No, it's not trivial to compile UNLESS you have qmake and Qt source. But just so you know, if you get Qt source now, you get QtConcurrent aswell. So why even bother downloading it stand-alone? Oh, and I almost forgot, Qt configure script generates some platform dependent source before compilation, so unless you compile Qt, your programs will have include errors.

The easiest way to try out QtConcurrent is to get qmake (which comes with Qt source you will also need). Qmake makes compilation a whole lot easier, so check out its documentation. It's actually not all that bad since Qt is an interesting API in itself and is worth checking out. It's huge but well documented and has a broad range of example applications lying about.

This page really helped me out when setting up my existing projects for QtConcurrent. Also if you looked at example source of the stand-alone version, include structure looks something like:

  1. #include <QList>
  2. #include <QMap>
  3. #include <QTextStream>
  4.  
  5. // local to project
  6. #include <map.h>
  7. #include <bind.h>
  8.  
  9. #include <QString>
  10. #include <QStringList>
  11. #include <QDir>
  12. #include <QTime>

Once you have the full-blown Qt you don't need any of these, they all come inside Qt (as of 4.4). The include files are called slightly differently, though. To make the word count example work you need to change "local" includes to:

  1. // qt concurrent stuff
  2. #include <QtConcurrentRun>
  3. // map.h
  4. #include <QtConcurrentMap>
  5. // To get Q_DECLARE_METATYPE(WordCount) working
  6. #include <QMetaType>