C++ QWinEventNotifier:无法从另一个线程(movetothread和qserialport)禁用事件通知程序

C++ QWinEventNotifier:无法从另一个线程(movetothread和qserialport)禁用事件通知程序,c++,qt,C++,Qt,#我很抱歉用这样的方式来描述这个消息,因为我是法语国家的人,我是这个论坛的初学者。我希望现在的评论更清晰 void Serie::Cfg() { serial = new QSerialPort(); _thrSerial = new QThread; this->moveToThread(_thrSerial); serial->moveToThread(_thrSerial); _thrSerial->start(); connect

#我很抱歉用这样的方式来描述这个消息,因为我是法语国家的人,我是这个论坛的初学者。我希望现在的评论更清晰

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;
  }
}

似乎
Serie
QSerialPort
的实例在不同的线程中运行,即使您在这两个线程上都调用了
moveToThread
。文档说,当对象有父对象时,
moveToThread
失败,您的
Serie
实例是否有父对象?moveToThread在正常情况下运行良好,除了关闭qserialport的端口,前面给出了beug。我使用一个系列类来声明我的线程。然后,Serie在主窗口中使用的另一个名为chargeur的类中声明为变量。void chargeur::initChargeur(QString com){{_serie=new serie(_com,QSerialPort::Baud115200,getInterFrame())}void main window::InstanceChargeur(QString acom,int avitesse){_chargeur=new chargeur(chargeur_ID)}当析构函数中出现问题时,似乎您从另一个线程调用了delete可能
deleteteLater
解决了这个问题似乎
Serie
QSerialPort
的实例在不同的线程中运行,即使您在这两个线程上都调用了
moveToThread
。文档说,当对象有父对象时,
moveToThread
失败,您的
Serie
实例是否有父对象?moveToThread在正常情况下运行良好,除了关闭qserialport的端口,前面给出了beug。我使用一个系列类来声明我的线程。然后,Serie在主窗口中使用的另一个名为chargeur的类中声明为变量。void chargeur::initChargeur(QString com){{_serie=new serie(_com,QSerialPort::Baud115200,getInterFrame())}void main window::InstanceChargeur(QString acom,int avitesse){_chargeur=new chargeur(chargeur_ID)}当析构函数中出现问题时,似乎您从另一个线程调用delete可能
deleteLater
解决了这个问题
`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.`