Qt Signals and Slot connected twice... what happens?

itapadar picture itapadar · Aug 20, 2010 · Viewed 17k times · Source

What happens if the same signal and slot is connected twice?

How is the mechanism handled?

Answer

San Jacinto picture San Jacinto · Aug 20, 2010

A few weeks ago, we had an intern accidentally connect a signal to a slot more than once. The idea was that under one condition, you'd have the slot connected to the signal, and under another condition you'd disconnect it. When you changed modes, you'd do the appropriate work.

Well, he forgot to to disconnect when appropriate. So every time you changed modes, you had a new connection to the slot.

The end result? 1 connection == 1 call to slot. 2 connections == 2 calls to slot. 3 connections == 3 calls to slot, etc. These calls happened "simultaneously" (I know in actuality they did not since they are on the same event thread, but what I mean was all calls were processed in succession).

As @Job points out in one of his comments (he deserves credit, so please do not upvote me for his work), Qt::UniqueConnection will prevent this issue.