直接进入主题:
基本用法,新建一个Widget类(父类无要求) ,在此基础上新建一个TestThread(必须继承自 QObject),
在Widget类构造函数里做如下处理:
m_TestThread = new TestThread();
m_thread = new QThread();
m_TestThread ->moveToThread(m_thread);
m_thread->start();//以上是必须滴
connect(this,SIGNAL(startThread()),m_TestThread ,SLOT(threadStart()));
emit startThread(); //发送信号,执行槽函数threadStart()
int i= 0;
while(1){
qDebug() <<"mainThread:"<<i++<<QThread::currentThreadId()<< endl;
QThread::msleep(1000);
}
TestThread类threadStart()槽函数代码
int i = 0;
while(1){
qDebug() <<"m_thread:"<< i++<< QThread::currentThreadId()<< endl;
QThread::msleep(1000);
}
结论一:

本文详细探讨了QT中moveToThread()的使用方法,通过实例展示了如何创建线程并确保主线程不被阻塞。同时,总结了线程运行、结束状态的判断以及相关信号与槽函数的应用,如started(), finished(), quit()和exit()。"
116204819,2978935,ionic native的cordova-plugin-webserver响应头问题及解决方案,"['typescript', 'cordova', 'plugin', 'java']
最低0.47元/天 解锁文章
410

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



