papercut87
10th August 2016, 08:12
Hi all, i'm trying to solve this problem.
I have a Qt object that does not inherit from QObject:
class A
{
public:
A();
~A();
B * bItem() const;
C * cItem() const;
QList<D *> dList() const;
void addDItem(D*item);
private:
B * m_bItem;
C * m_cItem;
QList<D*> m_dList;
};
#include "a.h"
A::A(){
this->m_bItem = new B;
this->m_cItem = new C;
}
A::~A(){
}
C * A::cItem() const{
return this->m_cItem;
}
B *A::bItem() const{
return this->m_bItem;
}
QList<D*> A::dList() const{
return this->m_dList;
}
void A::addDItem(D*item);{
this->m_dList.append(item);
}
I created an object A:
A a;
and i'm using it like a parameter in a SIGNAL\SLOT connection like this
connect( obj, SIGNAL( sig_message( A ) ), obj2, SLOT( slot_message( A ) ) );
All working fine in the signal\slot mechanism and i can use the A param without problems.
I saw also, when the scope of A param is finished, that the destructor of class A is called correctly.
My only question\doubt is:
how can i destroy the objects ( m_bItem , m_cItem and the list m_dList ) inside A?
They are pointers(and a list of objects pointers).
If use the delete function on those pointers the application crash.(during the emitting signal, maybe the destruction remove the object during the copy...).
Am I using a wrong pattern?
Any suggestion is appreciated.
Thanks in advance.
I have a Qt object that does not inherit from QObject:
class A
{
public:
A();
~A();
B * bItem() const;
C * cItem() const;
QList<D *> dList() const;
void addDItem(D*item);
private:
B * m_bItem;
C * m_cItem;
QList<D*> m_dList;
};
#include "a.h"
A::A(){
this->m_bItem = new B;
this->m_cItem = new C;
}
A::~A(){
}
C * A::cItem() const{
return this->m_cItem;
}
B *A::bItem() const{
return this->m_bItem;
}
QList<D*> A::dList() const{
return this->m_dList;
}
void A::addDItem(D*item);{
this->m_dList.append(item);
}
I created an object A:
A a;
and i'm using it like a parameter in a SIGNAL\SLOT connection like this
connect( obj, SIGNAL( sig_message( A ) ), obj2, SLOT( slot_message( A ) ) );
All working fine in the signal\slot mechanism and i can use the A param without problems.
I saw also, when the scope of A param is finished, that the destructor of class A is called correctly.
My only question\doubt is:
how can i destroy the objects ( m_bItem , m_cItem and the list m_dList ) inside A?
They are pointers(and a list of objects pointers).
If use the delete function on those pointers the application crash.(during the emitting signal, maybe the destruction remove the object during the copy...).
Am I using a wrong pattern?
Any suggestion is appreciated.
Thanks in advance.