How delete pointers to object that inherits from abstract class, using different threads!?



  • I'm sure that the problem I have is really common, but I can not imagine (maybe due to my QSharedPointer skills) how to solve it. I will try to explain myself:

    I have an ExampleBO class that inherits from AbstractBO. In adition, I have an AbstractDAO that have a signal with a AbstractBO* as parameter (I have tried to use a QSaredPointer to this fact). This signal sends ExampleBO* from OtherDAO class that inherits from the last one. My question is: how and where should I delete the pointer, that is passed as parameter, inside the signal? I have thought on using QSharedPointer to delete automatically this pointer when the references to this pointer decrease to zero, but I don't know how to do it. Here is my code:

    @class AbstractBO
    {
    public:
    AbstractBO();
    ~AbstractBO();

        virtual int getId() const = 0;
    
            int id;
    

    };@

    @class ExampleBO : public AbstractBO
    {
    public:
    ExampleBO(const int v1 = 0, const QString &v2 = QString());
    ~ExampleBO();

    private:
        int value1;
        QString value2;
    

    };@

    @class AbstractDAO : public QObject
    {
    Q_OBJECT

    signals:
        void sigQueryResponseOne(int queryId, QSharedPointer<AbstractBO> p_object, ErrorData p_errorInfo);
    
    public:
        AbstractDAO(QObject *parent = 0);
        virtual ~AbstractDAO() = 0;
    

    };@

    @class ExampleDAO : public AbstractDAO
    {
    Q_OBJECT

    public:
        ExampleDAO();
        ~ExampleDAO();
        QString getExamplesById_async(const int p_id)
        {
                ErrorData e;
                QSharedPointer<ExampleBO> example = QSharedPointer<ExampleBO>(new ExampleBO());
            
                emit sigQueryResponseOne(p_id, example, e);
        }
    

    };@

    My goal is how to send pointers to a class that inherits from the pure abstract base class between threads and delete them in the right way. Sometimes the problem is that we don't know who must delete the data of the pointer when it is sent between threads. I thought on sending objects but I have discarded it because I need to inherit some behaviour from the base class (that it is pure virtual).

    If someone has a happy idea, please share it with me!! :D


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.