我有无限的线程用于数据接收:
void RxFTDI::process() {
qDebug() << "RxFTDI hello!" << QThread::currentThreadId();
while(true)
{
FT_GetStatus(ftHandle,&RxBytes,&TxBytes,&EventDWord);
// FT_GetQueueStatus(ftHandle, &RxBytes);
if ((ftStatus == FT_OK) && (RxBytes > 0))
{
// qDebug() << "rx " << RxBytes;
FT_Read(ftHandle, &RxBuffer, RxBytes, &BytesReceived);
if (ftStatus == FT_OK) {
// FT_Read OK
}
else {
// FT_Read Failed
}
}
}
}
看起来当我想要使用 delete RxThread;
删除该线程时,我的应用程序会崩溃:
bool Ftdi::quitRxTxThreads ()
{
emit Tx->finished();
emit Rx->finished();
delete Tx;
delete Rx;
RxThread->terminate();
TxThread->terminate();
delete TxThread;
delete RxThread;
return true;
}
完整项目在github上: https://github.com/bLLAZ/ftQt 这个想法很简单。GUI和两个独立的线程:Tx和Rx。这是我第一个C++应用程序。如果您能看一下并给些建议如何更好地组织它,我将非常感激。
while(true)
。只需为其创建一个中断条件即可。;-) - StefanQThread
,因此可以考虑使用其中断机制。 - G.M.