qtconcurrent

Multithreading in QT using QtConcurrent

百般思念 提交于 2019-12-07 06:22:47
问题 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' instead a more traditional thread management, my code is simply: for(int i = 0; i < totalVideos; i++) { QFuture<ResultClass *> futureToken = QtConcurrent::run(this, process, listOfVideos.takeFirst()); QFutureWatcher<ResultClass *>* fw = new

std::bind, this and QtConcurrent

做~自己de王妃 提交于 2019-12-05 19:28:54
Im trying to use std::bind to bind this to method that is used in QtConcurrent::blockingMapped Header: class TuringMachine { private: TRTable table; std::set<ConfigNode*> currentConfigs; //function object std::function<std::set<ConfigNode*>( const TuringMachine*, ConfigNode*)> step_f; //method it will hold std::set<ConfigNode *> step(TuringMachine* this_m ,ConfigNode *parent); std::set<ConfigNode*>& makeStep(); } Source: TuringMachine::TuringMachine(/**/) { step_f = std::bind(&TuringMachine::step, this, std::placeholders::_1); } std::set<ConfigNode*> &TuringMachine::makeStep(){ auto configSet

Stop Thread started by QtConcurrent::run?

邮差的信 提交于 2019-12-05 11:43:54
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 startLiveCapturing-Method an infinite loop is running that captures images and displays them. So if the user wants to stop that process he should simply press a button and that operation stops. But it seems that i can not stop this thread by calling the cancel method like this ? this->cameraThreadRepresentation.cancel(); What i am doing wrong and how can i stop

Multithreading in QT using QtConcurrent

爱⌒轻易说出口 提交于 2019-12-05 11:43:54
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' instead a more traditional thread management, my code is simply: for(int i = 0; i < totalVideos; i++) { QFuture<ResultClass *> futureToken = QtConcurrent::run(this, process, listOfVideos.takeFirst()); QFutureWatcher<ResultClass *>* fw = new QFutureWatcher<ResultClass *>(); connect(fw, SIGNAL(finished()), this, SLOT(manageResult)); fw->setFuture

Connecting signals/slots on separate thread using QtConcurrent::run

谁说我不能喝 提交于 2019-12-05 06:02:43
问题 In my application I have the following code in a dialog: connect(drive, SIGNAL(FileProgressChanged(Progress)), SLOT(OnFileProgressChanged(Progress))); QtConcurrent::run(this, &ProgressDialog::PerformOperation, Operation, *Path, OutPath, drive); The PerformOperation function eventually calls to a function in drive which emits the signal FileProgressChanged , and my OnFileProgressChanged function is as follows: void ProgressDialog::OnFileProgressChanged(Progress p) { if (ui->progressCurrent-

Using QtConcurrent to load a Pixmap and paint it

送分小仙女□ 提交于 2019-12-04 17:25:14
I'm trying to create a Tile rendering program. Heres some basic code. Header class Tile: public QGraphicsItem { public: Tile(void); ~Tile(void); QGraphicsPixmapItem *tileItem; void update(QPainter *painter, const QStyleOptionGraphicsItem *option,QWidget *widget); protected: QRectF boundingRect() const; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,QWidget *widget); }; CPP: .Constructor etc . . void Tile::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,QWidget *widget) { if(tileItem==NULL) { qDebug()<<"Loading Pixmap"; QPixmap p("c:\\qt\\tile\\tile0-0.png"

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

跟風遠走 提交于 2019-12-03 02:26:19
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 worker thread. However, once the worker thread terminates, the QObject thread affinity should no longer be valid. The question: Does Qt automatically move the QObjects into the parent thread, or are we responsible in moving them to a valid thread before the worker thread terminates? QThread is not documented to automatically move any QObject s when it

QtConcurrent::map() with member function = can not compile

两盒软妹~` 提交于 2019-12-01 01:18:42
My project is to create a small program which demonstrates the work of a search engine: indexing and returning result for arbitrary queries. I've done the work with the indexer part and now I want to improve it with indexing multiple files at once. The MainWindow class is here: class MainWindow : public QMainWindow { Q_OBJECT ..... private: Indexer * indexer; QStringList fileList; .... void index(QStringList list); void add(const QString &filename); } This is the implementation of add ( add need to access fileList to avoid index the same files again, thus it can not be static method): void

QtConcurrent with member function

好久不见. 提交于 2019-11-30 21:25:36
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 runCompute(solveModel * model_); bool resultComput(); private: Manager *myMgr; QFuture<bool> myFutureCompute; }; where the methode runCompute() is creating the myFutureCompute member. .cpp looks like solveParallel::solveParallel(Manager* mgr_) :m_mgr(mgr_) { } solverParallel::~solverParallel(void){} void solverParallel::runCompute(solveModel* model) {

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

孤街浪徒 提交于 2019-11-28 20:37:57
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 better alternative to QThread is beyond me and would like some input. Kyle Lutz Yes, this is possible (and quite easy). Here is an example (from the Qt documentation): // call 'QStringList QString::split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const' in a separate thread QString string = ...; QFuture<QStringList> future =