Unable to create QtConcurrent::run - Reference to non-static member function must be called
-
Hello All,
I wanna multithread my current project so it doesn't block my GUI and all. I'm relatively new to QT and Cpp as a whole but was wondering if anyone could help me with this.
Qt Creator's suggestion to fix it involves adding brackets to the end, as shown, but results in an error saying No matching function for call to 'run'This is my code
QFuture<void> future = QtConcurrent::run(log, test);
And this is qt's suggested code
QFuture<void> future = QtConcurrent::run(log(), test);
All help is appreciated and, if possible, please explain something in the most simple of terms.
If I'm using the wrong way to multithread, please inform me of a better way.
-
@CoolSlimbo
Hello and welcome.Ignore the suggestion in this case, it's (doubtless) not what you are wanting!
The issue is as reported by your title: "Reference to non-static member function must be called". So could you start by explaining (show declarations of) what your parameters
log
&test
are? -
@CoolSlimbo said in Unable to create QtConcurrent::run - Reference to non-static member function must be called:
If I'm using the wrong way to multithread, please inform me of a better way.
It depends what you really want to do!
QtConcurrent::run()
is an easy way to move a "heavy computing" code into another thread and to get result when done.
So it is useful for "punctual" needs.You can also create a so called worker
QObject
based class which centralize all the computing, which will be triggered byslots
(to start a new calculation / task) and generatessignal
when result(s) is/are ready.
Then you can move the class instance to a thread to not "overload" the main thread (cf. https://mayaposch.wordpress.com/2011/11/01/how-to-really-truly-use-qthreads-the-full-explanation/) -
@KroMignon that blog post, while valid at that time can now be considered deprecated. The current QThread documentation covers the different possibilities very well and the folks at Woboq also provided follow up articles on that matter.
-
@JonB The
test
parameter was for the function, which was just a QString for the function, and the actual log was a function that logs the infomation to a file. I'm trying to fix this, because everytime my app starts up it has a lil bit of lag. I have 2 other functions I plan to test it on that are of a slightly heavier load, one reading a text file and interpreting it, and another generating widgets for my ui. -
@KroMignon Ignore what I'm using the QtConcurrent::run for. Just why do you think it's not working?
-
@CoolSlimbo
Your question wasbut results in an error saying No matching function for call to 'run'
so how can we "ignore
QtConcurrent::run()
" if that is the problem?