c++ - Passing a predicate to QWaitCondition? -


i'm writing threads in qt , can't figure out how pass predicate condition variable protect against spurious wake up.

working solution in c++:

std::mutex(mu); std::condition_variable cond;  std::unique_lock<mutex> alpha_lock(mu); cond.wait(alpha_lock, [](){ return //some condition;}); alpha_lock.unlock();  //continue stuff... 

qt equivalent:

qmutex mu; qwaitcondition cond;  qmutexlocker alpha_lock&(mu); cond.wait(&mu, [](){return //some condition;}) 

error:

"no matching member function call wait" 

any ideas on how use predicate in qt code?

as compiler , @xaxxon have pointed out, there no such wait() overload in qwaitcondition.

if want check condition before going on can this

while (!condition()) {     cond.wait(mutex); } 

you can of course put helper function takes qwaitcondition, qmutex , std::function if need in more places. or derive qwaitcondition adding overload doing loop above.


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -