Warnings for QKeyCombination deprecation after Qt6
-
Hi, I'm working on some warnings in our codebase.
I'm now at the following code:
auto keys = Qt::Key_R | Qt::CTRL | Qt::ALT; // warning: ^~~
Here, I get the following warning:
‘constexpr QKeyCombination::operator int() const’ is deprecated: Use QKeyCombination instead of int
The warning disappears for the following two variants:
auto keys = Qt::Key_R | Qt::ALT;
auto keys = Qt::CTRL | Qt::ALT | Qt::Key_R;
What's causing the warning here? How should I use
QKeyCombination
correctly? -
It wasn't really clear to me that using
Qt::CTRL | Qt::ALT
is still part of the usage. With that, the problem makes a lot more sense.Qt::Key_R | Qt::CTRL | Qt::ALT
evaluates to(Qt::Key_R | Qt::CTRL) | Qt::ALT
, which results inQKeyCombination | Qt::ALT
, which is what's raising the warning, sinceQKeyCombination
does not have any (non-deprecated) operators itself.Qt::CTRL | Qt::ALT | Qt::Key_R
instead evaluates to(Qt::CTRL | Qt::ALT) | Qt::Key_R
, which results inQt::Modifiers | Qt::Key_R
, which is an operation that is defined.This is kinda the answer I was looking for.
-
-
@Christian-Ehrlicher
I would not be making this post if I understood what that page is telling me. -
@Christian-Ehrlicher
I would not be making this post if I understood what that page is telling me. -
Just use this ctor and pass your key and modifiers - what else to say?
-
It wasn't really clear to me that using
Qt::CTRL | Qt::ALT
is still part of the usage. With that, the problem makes a lot more sense.Qt::Key_R | Qt::CTRL | Qt::ALT
evaluates to(Qt::Key_R | Qt::CTRL) | Qt::ALT
, which results inQKeyCombination | Qt::ALT
, which is what's raising the warning, sinceQKeyCombination
does not have any (non-deprecated) operators itself.Qt::CTRL | Qt::ALT | Qt::Key_R
instead evaluates to(Qt::CTRL | Qt::ALT) | Qt::Key_R
, which results inQt::Modifiers | Qt::Key_R
, which is an operation that is defined.This is kinda the answer I was looking for.
-