#我很抱歉描述这条消息的方式,因为我说法语,我是这个论坛的初学者。我希望现在评论更清楚
void Serie::Cfg()
{
serial = new QSerialPort();
_thrSerial = new QThread;
this->moveToThread(_thrSerial);
serial->moveToThread(_thrSerial);
_thrSerial->start();
connect(_thrSerial, SIGNAL(started()), this, SLOT(PortProcess()));
connect(_thrSerial, SIGNAL(finished()), this, SLOT(deleteLater()));
connect(_thrSerial, SIGNAL(finished()), _thrSerial, SLOT(terminate()));
connect(_thrSerial, SIGNAL(finished()), _thrSerial, SLOT(quit()));
}
void Serie::PortProcess()
{
connect(serial, SIGNAL(readyRead()), this, SLOT(Receive8bits()));//,Qt::QueuedConnection);
connect(serial, SIGNAL(error(QSerialPort::SerialPortError)), this, SLOT(ErrorHandle(QSerialPort::SerialPortError)));
connect(_thrSerial, SIGNAL(finished()), this, SLOT(deleteLater()));
}
void Serie::Receive8bits()
{
QByteArray lTmpByteArray = this->serial->readAll();
if(!lTmpByteArray.isEmpty())
{
for(int i= 0; i< lTmpByteArray.size(); i +=1)
{
lData = lTmpByteArray[i]& 0x000000FF;
FrameStateAdd(lData);
}
}
}
Serie::~Serie()
{
if(serial !=NULL)
{
if(serial->isOpen())
serial->close();//it is the source of problem
delete serial;// problem
serial = NULL;
}
}
当我决定关闭qserialport(serial)的端口时,我有这个错误:
`Invalid parameter passed to C runtime function.
ASSERT failure in QCoreApplication::sendEvent: "Cannot send events to objects owned by a different thread.
Current thread 122f1b28. Receiver '' (of type 'QSerialPort') was created in thread 146b8c40", file kernel\qcoreapplication.cpp, line 502.`