Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proper way to disconnect signals from two QObjects not being destroyed/deleted

What is the proper way to disconnect two QObject's from each other such that no more signals emitted from one object trigger slots in the other object? Neither object is going to be destroyed so disconnect() will not be called in QObject::~QObject(). I see two versions of the disconnect() method in the documentation, and neither one takes a pointer to two objects.

It is important that no more signals are received into the receiving objects slots after disconnect. A few triggers while the buffer clears unprocessed signals is OK, but the signals must stop within a very short time.

There seems to be some confusion about the proper way to do this.

like image 598
Freedom_Ben Avatar asked Mar 24 '23 14:03

Freedom_Ben


1 Answers

From the Qt docs:

[To] Disconnect a specific receiver:

disconnect(myObject, 0, myReceiver, 0);

Once this has been called, all connections from myObject's signals to myReceiver's slots will be disconnected.

like image 82
Matt Kline Avatar answered Apr 25 '23 04:04

Matt Kline