ustb_atrx
2018-05-07 09:41Qt 槽函数 两次调用 跨线程的信号槽函数(信号触发一次,槽函数被调用两次)
5WorkerThread* pWorkerThread = new WorkerThread;
pWorkerThread->moveToThread(&m_thread);
connect(this, &Dialog::sigSetCOM, pWorkerThread, &WorkerThread::slotSetCOM, Qt::QueuedConnection);
connect(this, &Dialog::sigSerialOpen, pWorkerThread, &WorkerThread::slotSerialOpen, Qt::QueuedConnection);
connect(this, &Dialog::sigSetFilePath, pWorkerThread, &WorkerThread::slotSetFilePath, Qt::QueuedConnection);
connect(pWorkerThread, &WorkerThread::sigSetProgressValue, this ,&Dialog::slotSetProgressValue, Qt::QueuedConnection);
connect(pWorkerThread, &WorkerThread::resultReady, this ,&Dialog::handleResults, Qt::QueuedConnection);
connect(pWorkerThread, &WorkerThread::sigBtOpenStateChange, this ,&Dialog::slotBtOpenStateChanged, Qt::QueuedConnection);
connect(pWorkerThread, &WorkerThread::sigResetState, this ,&Dialog::slotResetState, Qt::QueuedConnection);
connect(this, &Dialog::sigSend, pWorkerThread, &WorkerThread::slotSend);
connect(&m_thread, &QThread::finished, pWorkerThread, &QObject::deleteLater);
m_thread.start();
// 设置参数
//emit ui->serialPortName->currentIndexChanged(ui->serialPortName->currentText());
emit sigSetCOM(m_param);
上面的槽函数Dialog::slotBtOpenStateChanged(倒数第四个connect) 只连接了一次如下: connect(pWorkerThread, &WorkerThread::sigBtOpenStateChange, this ,&Dialog::slotBtOpenStateChanged, Qt::QueuedConnection);
按理说是pWorkerThread线程中信号WorkerThread::sigBtOpenStateChange触发后才会调用槽函数Dialog::slotBtOpenStateChanged,但是我的代码中只是在pWorkerThread触发了一次信号,而实际槽函数Dialog::slotBtOpenStateChanged却被调用了两次。一次与pWorkerThread有关。一次与Dialog有关,因为都有一个bool参数,Dialog触发的带的值不是我想要的。这与Dialog有关的多一次调用是为什么???
- 点赞
- 回答
- 收藏
- 复制链接分享
0条回答
为你推荐
- 全局函数如何和界面通讯?
- c++
- 5个回答
- qt中自定义槽函数怎么调用该类中的控件指针
- 控件
- qt
- 指针
- 2个回答
- TcpSocket对象发送数据后,没有触发bytesWritten信号
- qt
- 1个回答
- 想实现两次点击同一个按钮分别触发两个函数
- button点击事件
- 5个回答
- c++/qt 无法调用另一个cpp的函数
- 4个回答
换一换