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. How delete pointers to object that inherits from abstract class, using different threads!?
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 850 Views 1 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.
  • francescmmF Offline
    francescmmF Offline
    francescmm
    wrote on last edited by
    #1

    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

    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