Unsolved slot will be called multi-times if connect() multi-times, is there any way to check this error?
-
This post is deleted! -
@opengpu2 Do You have some reason for that?
Here is doc of connection types:
http://doc.qt.io/qt-5.5/qt.html#ConnectionType-enum -
@opengpu2 You can combine options: simply use
Qt::QueuedConnection | Qt::UniqueConnection
as last argument to theconnect
call -
Hi,
Connect doesn't overwrite anything, it just creates a new connection unless you use
Qt:UniqueConnection
like our fellows suggested.However that's an option that's rarely used, what is your use case ?
-
@SeeLook yep, cross thread use QueuedConnection
-
@Jakob so if i set Qt::UniqueConnection, that is equal to Qt::QueuedConnection | Qt::UniqueConnection. right?
-
@SGaist i wonder why Qt allow the same connect to be created multi-times... i wrongly wrote some connect in func except Constructor&Init(). and when that func is called multi-times, then each emit will cause multi-time slot...
i think Qt:UniqueConnection is set by default will be more safe.
can i write a custom macro to replace all connect and let them use Qt:UniqueConnection -
@Jakob i directly set the last param as Qt::QueuedConnection | Qt::UniqueConnection, but there is error canno convert from 'int' to 'Qt::ConnectionType'.
so i have to write like this? (Qt::ConnectionType)(Qt::QueuedConnection | Qt::UniqueConnection) -
While there are valid use cases, most of the time creating the exact same connection several times is a design/coding error so making UniqueConnection the default would just hide it and thus open the path to hard to debug behavior/bugs.
-
@SGaist ok thank you