Qt concurrent or std :: async for new code?

I am considering two options for running asynchronous code: Qt Concurrent and std::async . Given that I am writing a graphical application with Qt, it makes sense to go with Qt Concurrent. However, std::async also seems good and is supported by all major compilers.

Should I use Qt Concurrent or std::async for new code? What else should I look for when comparing the two?

+6
source share
2 answers

Given that I am writing a graphical application with Qt, it makes sense to go with Qt Concurrent

I would say this is not so simple. I personally would use the standard library as far as I can. However, there are limitations to consider:

Do you need to support your software on platforms that do not support at least C ++ 11?

If the question is yes, then using Qt solutions is the best option in Qt-based software. Even so, you may have different Qt solutions depending on your needs. One of the KDE weavers, but let's not go that far ...

Another question you could ask yourself:

Do you already have an existing code base, where is it used everywhere?

Depending on the answer, this can also provide an additional aspect of the solution, whether you prefer consistency or advanced thinking.

This also raises another question:

How much QtConcurrent do I need?

Depending on the exact answer, this may or may not be the best alternative. Please note that not all QtConcurrent functionality is in the standard library just yet, for example, something like QFutureWatcher with the Qt signal slot mechanism.

So, yes, as a Qt user, I would suggest using the standard library as much as possible. These days Qt even clearly depends on them, so it won’t work on a platform that does not support it. In addition, the general direction seems to be similar to this in the Qt project itself. For example, a QtAlgorithms been deprecated in QtAlgorithms , but this is only one of them.

+6
source

Qt Concurrent allows you to run a function in another thread using QtConcurrent::run() . So I think you can compare QtConcurrent::run() with std::async .

Qt Concurrent is so sophisticated and has many useful features. It includes APIs for parallel list processing and allows you to create multi-threaded programs without using low-level stream primitives, such as mutexes or semaphores. It also adjusts the number of threads used according to the number of processor cores available.

I think using Qt Concurrent is so cool due to its high-level APIs and ease of use.

+2
source

All Articles