diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2021-07-22 19:13:27 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2021-07-24 00:33:09 +0200 |
commit | a7da8e0dab8f6290b2af9bc12c0cd391af30bfb7 (patch) | |
tree | 5cd7fd3100336da8c78c53a9dca688f592367c20 /src | |
parent | bd594f945773f713ca493fd7b040fde8a12bdf87 (diff) |
QWidget: cope with QObject::connect()'s incomplete SFINAE-friendliness
The plan for QObject::connect() (perfect) forwarders, such as
QWidget::addAction(), was to just use a variant of the Detection Idiom
to see whether QObject::connect() with the arguments as given would
compile and SFINAE out the forwarder otherwise.
It turns out that the "functor" overload of QObject::connect(), in
particular, is severly underconstrained and accepts e.g. QKeySequence
as a function object, only erroring out via a static_assert() in the
body of the function, and thus at instantiation time and not, as
needed, at overload resolution time.
At the same time, we don't really want QObject::connect() to SFINAE
out on argument mismatches between signal and slot, because the
resulting error messages would be ... unkind to users of the API. We
would like to keep the static_assert()s for easier error reporting.
Reconciling these two contradicting requirements has so far eluded
this author, so for now, to unblock progress, we explicitly black-
and, in one case, white-list possible arguments. Because QKeySequence,
in particular, is implicitly constructible from int(!), and therefore
any enum type(!), incl. Qt::ConnectionType, we need to do way too much
coding in the addAction() constraints. Hopefully, we'll be able to fix
the issue at the root cause, in QObject, before Qt 6.3 is out, but
until then, this is an ok-ish stop-gap measure.
Add thorough overload set checks (positive ones only, for now) to
tst_qwidget and tst_qmenu.
Change-Id: Ia05233df818bc82ecc924fc44c1b349af41cbbf1
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/widgets/kernel/qwidget.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/widgets/kernel/qwidget.h b/src/widgets/kernel/qwidget.h index ee6e7d5fe6..6c30e018df 100644 --- a/src/widgets/kernel/qwidget.h +++ b/src/widgets/kernel/qwidget.h @@ -211,11 +211,28 @@ class Q_WIDGETS_EXPORT QWidget : public QObject, public QPaintDevice Q_PROPERTY(QString windowFilePath READ windowFilePath WRITE setWindowFilePath) Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ inputMethodHints WRITE setInputMethodHints) +#if 0 + // ### TODO: make this work (requires SFINAE-friendly connect()) template <typename...Args> using compatible_action_slot_args = std::void_t< decltype(QObject::connect(std::declval<QAction*>(), &QAction::triggered, std::declval<Args>()...)) >; +#else + // good-enough compromise for now + template <typename...Args> + using compatible_action_slot_args = std::enable_if_t<std::conjunction_v< +#if QT_CONFIG(shortcut) + std::disjunction< + std::is_same<Args, Qt::ConnectionType>, + std::negation<std::is_convertible<Args, QKeySequence>> + >..., +#endif + std::negation<std::is_convertible<Args, QIcon>>..., + std::negation<std::is_convertible<Args, const char*>>..., + std::negation<std::is_convertible<Args, QString>>... + >>; +#endif public: enum RenderFlag { DrawWindowBackground = 0x1, |