除了使用QThread创建线程之外,还可以使用C++thread创建线程。
1.首先在qt的.h文件中包含线程头文件
#include <thread>
2.创建线程执行函数
void MainWindow::thread1()
{
while(1)
{
}
}
3.创建线程对象,执行自定义线程函数
std::thread th1(&MainWindow::thread1,this);
4.分离线程对象,使之独自运行
th1.detach();