Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. DeleteLater and 2 slots
Forum Updated to NodeBB v4.3 + New Features

DeleteLater and 2 slots

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 218 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • qtprogrammer123Q Offline
    qtprogrammer123Q Offline
    qtprogrammer123
    wrote on last edited by qtprogrammer123
    #1

    Hi, i wonna ask if i have guaranti that deleteReplay slot will invoke after reciving slots - if i put deleteLater in reciving slots app crashing

    void Modbus::ModbusDevice::readOutputs(int addr, int count, QString name, int id, QModbusDataUnit::RegisterType registerType)
    {
        devName = name;
    
        QModbusDataUnit readUnit(registerType, addr, count);
    
        if (auto *reply = modbus->sendReadRequest(readUnit, 1)) {
            if (!reply->isFinished()) {
                if(id == 3) {
                    connect(reply, &QModbusReply::finished,this,&ModbusDevice::onReadOutputsFinished);
                }
                else connect(reply, &QModbusReply::finished,this,&ModbusDevice::onReadFinished);
                
                connect(reply, &QModbusReply::finished, this, &ModbusDevice::deleteReply);
                
            } else {
                delete reply;
            }
        }
    }
    void Modbus::ModbusDevice::deleteReply()
    {
        QModbusReply *reply = qobject_cast<QModbusReply *>(sender());
        reply->deleteLater();
    }
    

    Mam moc jak Harry Potter, w zębach mogę przenieść hotel.

    jsulmJ 1 Reply Last reply
    0
    • qtprogrammer123Q qtprogrammer123

      Hi, i wonna ask if i have guaranti that deleteReplay slot will invoke after reciving slots - if i put deleteLater in reciving slots app crashing

      void Modbus::ModbusDevice::readOutputs(int addr, int count, QString name, int id, QModbusDataUnit::RegisterType registerType)
      {
          devName = name;
      
          QModbusDataUnit readUnit(registerType, addr, count);
      
          if (auto *reply = modbus->sendReadRequest(readUnit, 1)) {
              if (!reply->isFinished()) {
                  if(id == 3) {
                      connect(reply, &QModbusReply::finished,this,&ModbusDevice::onReadOutputsFinished);
                  }
                  else connect(reply, &QModbusReply::finished,this,&ModbusDevice::onReadFinished);
                  
                  connect(reply, &QModbusReply::finished, this, &ModbusDevice::deleteReply);
                  
              } else {
                  delete reply;
              }
          }
      }
      void Modbus::ModbusDevice::deleteReply()
      {
          QModbusReply *reply = qobject_cast<QModbusReply *>(sender());
          reply->deleteLater();
      }
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @qtprogrammer123 said in DeleteLater and 2 slots:

      QModbusReply *reply = qobject_cast<QModbusReply *>(sender());
      reply->deleteLater();

      You're not checking the pointer: if it's nullptr it will crash.
      You're connecting QModbusReply::finished to ModbusDevice::deleteReply and to ModbusDevice::onReadFinished - why don't you simply call deleteLater inside ModbusDevice::onReadFinished?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved