Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. problems when deleting class inherit
Forum Updated to NodeBB v4.3 + New Features

problems when deleting class inherit

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 4 Posters 917 Views 3 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.
  • K Offline
    K Offline
    kickoune103
    wrote on last edited by
    #1

    hello,
    i have problem, i have segmentation fault when i deleting inherit class. executing destructor.i have delete all signal. same problems.
    i delete tx_rs_modbus, call delete tx_rs_device and seg fault!

    it's crazy...
    please help me.

    img debug

    base class:

    //your code here
    ```class tx_rs_device:public QObject
    {
       Q_OBJECT
    
    
    public:
        tx_rs_device(Trame* Parent);
        ~tx_rs_device();
    
        const int GetIntervalTx();
        void SetIntervalTx( int pint );
    
        const QString getTrameTx();
        void setTrameTx(QString pTx);
    
        void start();
    
        QVariantList getConf(void);
        void  setConf(QVariantList);
    
    
        tx_rs_modbus *getModbustx();
    
        bool traiteRecuRx();
    
        QTime getTimeLastTx();
    
        void sendTx();
    
    
    
     enum enumModeTx{MANUEL,ONE_SHOT,CYCLIQUE,AUTO};
    
    //signals:
     //void started();
    
    protected:
            Trame       *MaTrame;
            enumModeTx  m_ModeTx;
            QString     m_TrameTx;
            QTimer      m_TimerTx;
    
            quint32     cptTx;
            quint32     cptTxOK;
            quint32     cptTxKO;
            QTime       m_TicksLastTx;
    
            bool        TxEnCours;
           // bool        first;
           // bool        RxRecu;
    
    public slots:
           virtual void requeteTx();
            void timeOut();
    };
    class tx_rs_modbus:public tx_rs_device
    {
        Q_OBJECT
    
    
     public:
        enum enumTypeTx{WRITE=0,READ};
    
         tx_rs_modbus(Trame* Parent,enumTypeTx pType);
         tx_rs_modbus(Trame* Parent,enumTypeTx pType,bool pWrite);
    
         ~tx_rs_modbus();
    
    
    
          enumTypeTx getTypeTx(void);
          void setTypeTx(enumTypeTx pType);
    
          QModbusDataUnit::RegisterType getTypeRegister();
           void setTypeRegister(QModbusDataUnit::RegisterType pRegister);
    
           int  getAdresseModbus();
           void setAdresseModbus(int pAdresse);
    
           QVariantList getConf();
           void setConf(QVariantList pConf);
    
    private:
          enumTypeTx  m_type_tx;
          bool        writeWhenChange;
          QByteArray  *m_byte_array_remote;
          QModbusDataUnit::RegisterType m_type_register;
          int m_adresse;
          //int m_periode_tx;
    
            bool m_reply;
    
       public slots:
         void isStarted();
         void TrameChange(); //quand les champs.
         void requeteTx();
         void reply();
    };
    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      Could it be a double delete ?
      If you assign parent ( Trame *) to it , the parent will delete its child automatically, so if you manually call delete on the child,
      it might result in double delete.

      http://doc.qt.io/qt-5/objecttrees.html

      1 Reply Last reply
      3
      • K Offline
        K Offline
        kickoune103
        wrote on last edited by
        #3

        in class Trame, have a properties tx_rs_modbus*,
        when i deleting this to create a new trame object, i deleting properties to create a other.
        delete tx_rs_modbus call a delte tx_rs_device and seg fault...

        jsulmJ 1 Reply Last reply
        0
        • K kickoune103

          in class Trame, have a properties tx_rs_modbus*,
          when i deleting this to create a new trame object, i deleting properties to create a other.
          delete tx_rs_modbus call a delte tx_rs_device and seg fault...

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @kickoune103 Do I understand you correctly: you're calling base class destructor explicitly? This is not needed. Can you show both destructors?

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

          1 Reply Last reply
          1
          • K Offline
            K Offline
            kickoune103
            wrote on last edited by
            #5
            //trame rs is tx_rs_device.
            
                union t_trame_rs{
                        tx_rs_device *tx;
                        rx_rs *rx;
                };
            
            //on my case trame_rs_tx is allocate with new tx_rs_modbus().
            
            ```void Trame::kill_m_trame()
            {
            
                switch ( MonProt->GetILiaison())
                {
                   case Protocole::LIAISON_RS:
                    switch (m_TypeTrame)
                    {
                       case TRAME_TX:
                        qDebug() << "kill rs tx";
                         delete this->m_trame.trame_rs.tx;
                        this->m_trame.trame_rs.tx = NULL;
                        break;
            
                       case TRAME_RX:
                        qDebug() << "kill rs rx";
                        delete this->m_trame.trame_rs.rx;
                         this->m_trame.trame_rs.rx = NULL;
                        break;
            
                    }
                    break;
                   case Protocole::LIAISON_CAN:
                            switch (m_TypeTrame)
                            {
                               case TRAME_TX:
                                qDebug() << "kill can tx";
                                delete this->m_trame.trame_can.tx;
                                this->m_trame.trame_can.tx = NULL;
                                break;
            
                               case TRAME_RX:
                                qDebug() << "kill can rx";
                                delete this->m_trame.trame_can.rx;
                                this->m_trame.trame_can.rx = NULL;
                                break;
            
                            }
                       break;
                }
            }
            
            //no code in destructor.
            tx_rs_device::~tx_rs_device()
            {
            qDebug() << "delete tx rs";
            }
            tx_rs_modbus::~tx_rs_modbus()
            {
                qDebug() << "delete tx modbus";
                m_TimerTx.stop();
            }
            
            
            thanks
            1 Reply Last reply
            0
            • K Offline
              K Offline
              kickoune103
              wrote on last edited by
              #6
              //in main.c, little example, blocking in destructor of tx_rs_device.
              //i have created "*tx_modbus" in t_trame_rs (tx_rs_modbus *tx_modbus)
              //nothing change.
              
              
              
                   l_prot.SetiLiaison(Protocole::LIAISON_RS);
                   l_prot.SetIprot(Protocole::PROT_RS_MODBUS);
              
               Trame *ptTrame = new Trame(&l_prot,"");
              
               qDebug() << "test delete";
               //ptTrame->setTypeTrame(Trame::TRAME_TX);
               delete ptTrame->getTrame().trame_rs.tx_modbus;
               qDebug() << "test delete";
              
              jsulmJ 1 Reply Last reply
              0
              • K kickoune103
                //in main.c, little example, blocking in destructor of tx_rs_device.
                //i have created "*tx_modbus" in t_trame_rs (tx_rs_modbus *tx_modbus)
                //nothing change.
                
                
                
                     l_prot.SetiLiaison(Protocole::LIAISON_RS);
                     l_prot.SetIprot(Protocole::PROT_RS_MODBUS);
                
                 Trame *ptTrame = new Trame(&l_prot,"");
                
                 qDebug() << "test delete";
                 //ptTrame->setTypeTrame(Trame::TRAME_TX);
                 delete ptTrame->getTrame().trame_rs.tx_modbus;
                 qDebug() << "test delete";
                
                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @kickoune103 What is tx in m_trame.trame_can.tx and how is it initialised?

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

                1 Reply Last reply
                0
                • K Offline
                  K Offline
                  kickoune103
                  wrote on last edited by
                  #8

                  solved..
                  setParent(this) in the software....

                  sorry

                  Pablo J. RoginaP 1 Reply Last reply
                  0
                  • K kickoune103

                    solved..
                    setParent(this) in the software....

                    sorry

                    Pablo J. RoginaP Offline
                    Pablo J. RoginaP Offline
                    Pablo J. Rogina
                    wrote on last edited by
                    #9

                    @kickoune103 please don't forget to mark your post as solved. Thanks.

                    Upvote the answer(s) that helped you solve the issue
                    Use "Topic Tools" button to mark your post as Solved
                    Add screenshots via postimage.org
                    Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                    1 Reply Last reply
                    0

                    • Login

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