how to create a new thread in Qt?
-
what is the normal way to create a new thread? (i want sth like ::CreateThread in window)
-
The documentation is your friend.
Also, if you just want to start some function asynchronously, you can take a look at QtConcurrent::run(...). -
QtConcurrent::run....what is it advantage?
and can i send a member func to it? eg. Mainwindow:func()...
or is it better to use a global func to send to it?and what should i do when the app quit or close?
how should i stop it if i want?
-
can i write like this?
QtConcurrent::run(func, p);before the main()
@
void func(pointer* p)
{
Class* xxx = new Class();
while (p->Running())
{
xxx->tick();
}
delete xxx;
return;
}
@when my app is closed, i set the global p make the p->Running()==false in the mainthread.........does this work???
//ps. can func have return value? does it make sense?
-
@opengpu2 said:
QtConcurrent::run....what is it advantage?
There are a few different ways to use threads in Qt. This page tries to explain how to choose: http://doc.qt.io/qt-5/threads-technologies.html