problems when deleting class inherit
-
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.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(); };
-
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. -
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... -
@kickoune103 Do I understand you correctly: you're calling base class destructor explicitly? This is not needed. Can you show both destructors?
-
//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
-
//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";
-
@kickoune103 What is tx in m_trame.trame_can.tx and how is it initialised?
-
solved..
setParent(this) in the software....sorry
-
@kickoune103 please don't forget to mark your post as solved. Thanks.