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

QModbusReply would never finished after QModbusRtuSerialMaster was closed

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2: Important
    • Resolution: Done
    • Affects Version/s: 5.9.2
    • Fix Version/s: 5.12.0 Beta 4
    • Component/s: SerialBus: MOD Bus
    • Labels:
      None
    • Commits:
      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

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            Assignee:
            ablasche Alex Blasche
            Reporter:
            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