Nyaruko
Nyaruko

Reputation: 4459

Will the connection be disconnected in Qt automatically?

From the problem here: Qt Signals and Slots object disconnect? If I first call the delete on a QObject, then I call the disconnect function like this:

MyQClass* A = new MyQClass();
connect(A,SIGNAL(A_S()),this,SLOT(B_S()));
A->deleteLater();
...
disconnect(A,SIGNAL(A_S()),this,SLOT(B_S()));

Will this cause a crash? I found it cause a crash under Qt4, but not Qt5? Is the different Qt version doing something different? Otherwise, there might be something else wrong with my code.

Upvotes: 1

Views: 1300

Answers (1)

Silicomancer
Silicomancer

Reputation: 9156

Connections are disconnected automatically on object destruction. The crash probably happens because you are trying to call disconnect on an object that was destroyed. You are getting a dangling pointer A (having an address to an object that does not exist anymore). But this depends a little an what "..." is.

Upvotes: 2

Related Questions