Unsolved QThread * create(Function &&f)
-
Hi,
Based on the documentation of the create method, something like:
// somewhere: void myFunction(int arg1, int arg2) { qDebug() << Q_FUNC_INFO << arg1 << arg2; } // somewhere suitable: QThread *myThread = QThread::create(myFunction, 12, 30);
-
Note: this function is only available when using C++17.
Does VS2015 support C++17?
If yes, did you enabled it withCONFIG+=c++17
in the .pro file? -
@sgaist
Thanks for your reply.
The example you mentioned is correct. But in my code, XferLoop() is the member function of class a. So it shows the error-Parameter list mismatch. The function XferLoop() calls many private variables of class a.
QThread::create(Function &&f) dosen't need C++17, but the QThread::create(Function &&f, Args &&... args) does. -
@qt_crazyer said in QThread * create(Function &&f):
QThread::create(Function &&f) dosen't need C++17, but the QThread::create(Function &&f, Args &&... args) does.
Sorry my fault!
-
a::a :XferThread(QThread::create(std::bind(&a::XferLoop,this)) { }
The function XferLoop() calls many private variables of class a.
hic sunt leones. Be very careful not to create race conditions
-
You can also use a lambda which is preferred over std::bind:
a::a(): XferThread(QThread::create([this](){XferLoop();}) {}
-
@AshkanV said in QThread * create(Function &&f):
which is preferred over std::bind
One of them catch-all phrases, eh? Says who, and why is it supposedly preferred?
-
-
Okay, so I found out about the "who". Now if you can convince me that "it is preferred" is the same as "clang tidy says it's preferred" ...
I remember there was this one guy who said everything should beauto
because reasons. Recently there was this other guy (here) that didn't realize usingauto
broke his code ... stuff happens, I guess ... -
@kshegunov said in QThread * create(Function &&f):
Now if you can convince me that "it is preferred" is the same as "clang tidy says it's preferred" ...
No, no need to convince you. :)
I prefer lambdas because I never understood std::bind() and I need to think about it every time I see such a call :) -
@Christian-Ehrlicher said in QThread * create(Function &&f):
I prefer lambdas
Such reasoning I can live with, even without any justification. I just grumble at the catch-it-all-no-need-to-think-about-it sort of statement(s).