#include <thread>
void ThreadDlg::thread_fun(int nValue)
{
for (int i = 0; i < nValue; i++)
{
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
}
}
void ThreadDlg::thread_fucAdd(int nValue, int nValue1)
{
int nResult = 2 * nValue + nValue1;
}
void ThreadDlg::on_btnTestThread_clicked()
{
std::thread myThread(&ThreadDlg::thread_fun, this, 10);
myThread.detach();
std::thread myThread1(&QtTestCppThread::thread_fucAdd, this, 10, 20);
myThread1.detach();
}
纯C++方式创建线程
于 2023-08-15 16:39:10 首次发布
博客展示了使用C++和Qt实现多线程的代码。定义了`thread_fun`和`thread_fucAdd`两个函数,前者进行循环休眠,后者进行简单的数学计算。在`on_btnTestThread_clicked`函数中创建并分离了两个线程,分别调用上述函数。

866

被折叠的 条评论
为什么被折叠?



