Hi Peppe,
thank you alot for this highly appreciated and super useful feature!
Give up counting how often I forgot the context argument.
Ciao
Mathias
Am 10.07.2023 um 18:02 schrieb Giuseppe D'Angelo via Development:
Hi,
https://codereview.qt-project.org/c/qt/qtbase/+/487560 introduces
QT_NO_CONTEXTLESS_CONNECT , a macro that disables the 3-arguments
connect -- in other words, it disables the
QObject::connect(sender, signal, functor)
overload, leaving only 4/5 argument(s) overloads
QObject::connect(sender, signal, receiver/context, functor/slot, (type))
as well as the string-based connect().
The reason for NOT using the 3-args overload is that it is error prone.
For starters, it makes it hard to reason about the lifetime of such a
connection. It makes it very easy to connect to lambdas that capture
some local state in the receiver, but when the receiver is destroyed,
the connection isn't automatically disconnected (therefore, if the
signal is emitted, the program will crash). Fixing this may or may not
be straightforward, depending on how much state is captured.
Second, it's also easy to forget that since there's no
receiver/context, the connection is always forced to be *direct*,
which complicates things if multiple threads are involved.
--
I'm about to enable the macro for (most) of QtBase:
https://codereview.qt-project.org/c/qt/qtbase/+/489232
I've also done the exercise of enabling it for qtdeclarative (patches
pending) and qttools (merged), but there's simply too much code out
there that *still* uses it. As I said above, fixes are not always
obvious (sometimes it's very unclear who the "receiver" is).
--
Since this is ultimately a code style issue, I'd like to leave the
decision with the module maintainers regarding whether or not enable
QT_NO_CONTEXTLESS_CONNECT for their own modules. Ideally, however, we
should enable it in headersclean, so please make at least those not
contain 3-args connect().
Opinions? Objections?
Thank you,
--
Development mailing list
Development@qt-project.org
https://lists.qt-project.org/listinfo/development