Questions tagged [qtconcurrent]

QtConcurrent is a Qt framework namespace providing high-level multithreading APIs.

QtConcurrent namespace was introduced in Qt 4.4. The QtConcurrent namespace provides high-level APIs that make it possible to write multi-threaded programs without using low-level threading primitives such as mutexes, read-write locks, wait conditions, or semaphores.

As of Qt 4.8.0, it includes:

  • 2 Classes
  • 2 Types
  • and mostly Functions

As of Qt 5, it became a separate add-on module, and includes:

  • QtConcurrent namespace
  • QFuture
  • QFutureIterator
  • QFutureWatcher
  • QFutureSynchronizer

Details can be found on the following page.

Resources:

193 questions
26
votes
6 answers

What happens to the thread affinity of a QObject created within a worker thread which then terminates?

Let's say I call QtConcurrent::run() which runs a function in a worker thread, and in that function I dynamically allocate several QObjects (for later use). Since they were created in the worker thread, their thread affinity should be that of the…
Alexander Kondratskiy
  • 4,156
  • 2
  • 30
  • 51
20
votes
2 answers

is it possible to use QtConcurrent::run() with a function member of a class

I can't seem to be able to associate QtConcurrent::run() with a method (function member of a class) only with a simple function. How can I do this? With a regular function I cannot emit signals and its a drag. Why would anyone find this a…
yan bellavance
  • 4,710
  • 20
  • 62
  • 93
18
votes
5 answers

QFuture that can be cancelled and report progress

The QFuture class has methods such as cancel(), progressValue(), etc. These can apparently be monitored via a QFutureWatcher. However, the documentation for QtConcurrent::run() reads: Note that the QFuture returned by QtConcurrent::run() does not…
Dave Mateer
  • 17,608
  • 15
  • 96
  • 149
18
votes
2 answers

Multithreading performance of QtConcurrent Vs QThread with many threads

Suppose your application needs to run a function in multiple threads the number of which is more than the number of CPU cores/threads. One way is to use QtConcurrent and setting the maximum thread count : MyClass *obj = new…
Nejat
  • 31,784
  • 12
  • 106
  • 138
8
votes
3 answers

QtConcurrent in PySide/PyQt

I'm trying to figure out if subclassing QtConcurrent and writing a run method inside it will work: class Task(QtCore.QtConcurrent): def run(self, function): function() Or is it completely useless?
Elteroooo
  • 2,913
  • 3
  • 33
  • 40
8
votes
2 answers

Qt Concurrent or std::async for new code?

I'm considering two options to run asynchronous code: Qt Concurrent and std::async. Given that I'm writing a GUI app with Qt, it makes sense to go with Qt Concurrent. However std::async also seems good and supported by all major compilers. Should I…
galymzhan
  • 5,505
  • 2
  • 29
  • 45
7
votes
2 answers

Qt concurrent run, pass value by reference, but the memory address is different?

I use QtConcurrent::run to run a function, and pass value by reference, but the memory address of value is different. But if I pass value by pointer, the address is the same! I can't figure it out. Do I miss something? Here's code. void ptr(QString*…
movef
  • 368
  • 3
  • 8
7
votes
2 answers

How to communicate a progressText from a QtConcurrent::run function (or similar) to a QFutureWatcher?

If I launch some function for asynchronous execution using QtConcurrent::run, and am monitoring the returned future using a QFutureWatcher, what if anything can I do in that asynchronously executing function to communicate some progress text back…
timday
  • 24,582
  • 12
  • 83
  • 135
7
votes
1 answer

Updating a QProgressDialog with a QFuture

What's the proper way for the main GUI thread to update a QProgressDialog while waiting for a QFuture. Specifically, what goes in this loop: QProgressDialog pd(...); QFuture f = ...; while (!f.isFinished()) { pd.setValue(f.progressValue()); //…
Alex77
  • 101
  • 2
  • 6
6
votes
13 answers

How to reduce CPU usage of a program?

I wrote a multi-threaded program which does some CPU heavy computation with a lot of floating point operations. More specifically, it's a program which compares animation sequences frame by frame. I.e. it compares frame data from animation A with…
sneg
  • 2,088
  • 4
  • 19
  • 23
6
votes
3 answers

Stop Thread started by QtConcurrent::run?

Is it possible to stop a Thread by its associated QFuture Object ? Currently i've been starting a video capturing process like this. this->cameraThreadRepresentation = QtConcurrent::run(this,&MainWindow::startLiveCapturing); Inside the…
Sebastian Boldt
  • 5,283
  • 9
  • 52
  • 64
6
votes
1 answer

QRunnable - how to use it, examples

Could point at some code using QRunnable as an alternative to QtConcurrent: I can't find any QRunnable example in Qtdoc. Did you ever try QRunnable AND QtConcurrent for same application, and could you comment on the compared performance?
kiriloff
  • 25,609
  • 37
  • 148
  • 229
5
votes
1 answer

QtConcurrent with member function

I create a QFuture that I want to use to parallelize calls to a member function. More precisely, I have a class solveParallel with .h : class solverParallel { public: solverParallelData(Manager* mgr_); virtual ~solverParallel(void); void…
kiriloff
  • 25,609
  • 37
  • 148
  • 229
5
votes
1 answer

Multithreading in QT using QtConcurrent

Im developing an application in Qt which, at some point, process a bunch of videos. It works fine but it had only a 40-60% of the cpu usage during the process phase so i tried to make it multithreaded. I used QtConcurrent cause his 'high leveness'…
Sommerwild
  • 506
  • 1
  • 6
  • 18
5
votes
2 answers

QtConcurrent::run() can't handle more than 5 arguments?

I'm getting a compile error when passing a function with 6 parameters or more to QtConcurrent::run(). When I reduce them to 5 parameters, I no longer get this error. This dummy code reproduces the error for me: void foo(int, int, int, int, int,…
sashoalm
  • 75,001
  • 122
  • 434
  • 781
1
2 3
12 13