Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Would the slot get called multiple times if I connect the same slots for multiple times?

If I connect the same signal with the same slot twice, would this cause a bug? e.g the slot get called twice when the signal is emitted?

like image 368
daisy Avatar asked Feb 19 '23 15:02

daisy


1 Answers

Short answer: Your slot would be called twice.

Whether this causes bugs or is the desired behaviour depends on your application of course.

In most cases it is probably not wanted, so to prevent this you can either track your connections, use disconnect first or if you are using at least Qt 4.6 there is a new connection type Qt::UniqueConnection which prevents duplicate connections automatically and otherwise behaves like Qt::AutoConnection, see connection types and a blog post about the new unique type.

like image 162
Steffen Avatar answered Apr 29 '23 12:04

Steffen