Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-68543

QModbusReply would never finished after QModbusRtuSerialMaster was closed

    XMLWordPrintable

Details

    • 834258bb3d17638e8e3dc2eca2a3115006c092fd (qt/qtserialbus/5.12)

    Description

      // code placeholder
      void    BlockedModbusMaster::waitFinished (QModbusReply *reply)
      {
          if (reply != nullptr)
          {
              while (!reply->isFinished())
              {
                  QEventLoop  loop;
                  connect(reply, SIGNAL(finished()), &loop, SLOT(quit()), Qt::QueuedConnection);
                  connect(reply, SIGNAL(errorOccurred(QModbusDevice::Error)), &loop, SLOT(quit()), Qt::QueuedConnection);
      
                  qDebug("enter loop");
                  loop.exec();
                  qDebug("exit loop");
              }
          }
      }
      

      Above is my code, and I found the loop never quit after the

      QModbusRtuSerialMaster was closed via disconnectDevice.

       

      I viewed the qtserialbus source code, in the file "qmodbusrtuserialmaster_p.h", the object "m_current" was unhandled when the serialport was aboutToClose. I think this is exactly the reason why the QModbusReply never finished, am I correct?

      // code placeholder
      QObject::connect(m_serialPort, &QSerialPort::aboutToClose, q, [this]() {
      Q_Q(QModbusRtuSerialMaster);
      Q_UNUSED(q); // To avoid unused variable warning in release mode
      Q_ASSERT(q->state() == QModbusDevice::ClosingState);
      
      m_sendTimer.stop();
      m_responseTimer.stop();
      });
      

      Attachments

        For Gerrit Dashboard: QTBUG-68543
        # Subject Branch Project Status CR V

        Activity

          People

            ablasche Alex Blasche
            moral Minghao Wang
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes