在多线程中,主线程输出数据,与传递到多线程输出数据对此。结论:数据输出是按照信号、槽函数等的先后执行顺序,没有优先级,只是在系统调试输出时,qDebug()有输出顺序,但是不会改变参数的变化。
//在UI线程中定义
qDebug()<<QThread::currentThread()->objectName()<<"index start";
indexxx = 0;
qDebug()<<QThread::currentThread()->objectName()<<"index=0输出为:"<<indexxx;
indexxx++;
qDebug()<<QThread::currentThread()->objectName()<<"在tt(index)信号前 index=1 输出为:"<<indexxx;
emit tt(indexxx);
indexxx++;
qDebug()<<QThread::currentThread()->objectName()<<"在ui->pushButton_2->click()信号前 index=2 输出为:"<<indexxx;
ui->pushButton_2->click();
indexxx++;
qDebug()<<QThread::currentThread()->objectName()<<"index finished"<<indexxx;
其中connect(this, SIGNAL(tt(int)), b1, SLOT(ss(int))); b1为子线程,
void B::ss(int dexx){qDebug()<<QThread::currentThread()->objectName()<<"tt(index)信号传递过来index=1输出为:"<<dexx;}
系统输出顺序是:
"在主线程UI" index start
"在主线程UI" index=0输出为: 0
"在主线程UI" 在tt(index)信号前 index=1 输出为: 1
"在主线程UI" 在ui->pushButton_2->click()信号前 index=2 输出为: 2
"在子线程Name_threadAS" tt(index)信号传递过来index=1输出为: 1
"在主线程UI" 在ui->pushButton_2->click()槽函数中 index=2 输出为: 2
"在主线程UI" index finished 3
子线程输出有些滞后,应该是信号与槽函数传递需要耗费时间,但是传递的参数数值没有变化。
QThread::currentThread()->setObjectName("在主线程UI");可以设置线程的名字
1万+

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



