Y
Y
Yu Yu2018-02-21 19:47:27
Qt
Yu Yu, 2018-02-21 19:47:27

What happens if you override the destructor in a class derived from QObject?

As far as I know, the QObject class in Qt carries special functions for tracking objects and removing them itself.
I need to execute a function when an object is deleted, so I overridden the destructor. What does it threaten? In general, in Qt, you can make your own destructors, knowing that the object itself monitors its descendants?
class MyClass : public QObject
{
Q_OBJECT
public:
explicit MyClass(QObject *parent = nullptr);
~MyClass();
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis Zagaevsky, 2018-02-21
@xztau

I think that qt was not written by idiots, and there, after all, there is a virtual destructor, as it should be for classes intended for inheritance. Everything will be OK.

S
Stanislav Makarov, 2018-02-22
@Nipheris

I need to execute a function when an object is deleted, so I overridden the destructor.

Why did you decide that the destructor of the base class, i.e. the behavior that would work without your override will NOT be invoked?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question