using a thread for running a function
-
hello guys again,
i'm trying to use a thread to run a function with Argument, the function is on a big class that interact with several display i need to use the thread only for one or 2 function.
so i don't wont to use my thread for all the class.
the function is called when we push enterbutton so i think i should connect the thread to my function after the pushbutton
so how can we do to use the thread just for a function not all the class ?i saw that some people are using moveToThread but they are connecting it to a class perhaps i didn't undertood well what they doing so need you help please
bool copyPath(QString sourceDir, QString destinationDir, bool overWriteDirectory) { // using thread for this function // thread start ........... if(condition==true) // thread stoped ; retrun true }
thanks for help :)
-
@benamiar Take a look at https://doc.qt.io/qt-5/qtconcurrentrun.html
-
i did that and i got an erreur wish speak about a non static function memebr
QFuture<bool> future = QtConcurrent::run(copyPath,pathSrc,pathDes,false);
erreur : invalid use of non-static member function
QFuture<bool> future = QtConcurrent::run(copyPath,pathSrc, pathDes, false);whats wrong with that line ?
^ ^ -
@benamiar said in using a thread for running a function:
copyPath
Your copyPath() function should be static (I think).
-
@benamiar said in using a thread for running a function:
QFuture<bool> future = QtConcurrent::run(copyPath,pathSrc,pathDes,false);
IIRC run wants a function pointer?
QFuture<bool> future = QtConcurrent::run(this, &myClass::copyPath,pathSrc,pathDes,false);
-
This post is deleted!