ARTICLE AD BOX
I am trying to clear out deprecation warnings in Qt v6.10, MinGW on Windows 11. I am getting warnings on this code (variables like spdVal, ssss are defined in code above these lines):
void acquireDataDlg::adjustErgoSettings(QKeyCombination key, short ergo) { ... // local variables defined in top section switch(key) { case (Qt::Key_A | Qt::ShiftModifier): spdVal= (spdVal < 10 * ssss) ? 0.0 : (spdVal - 10 * ssss); break; case(Qt::Key_S | Qt::SHIFT): spdVal+= 10 * ssss; break; default: errOut=true; break; } }The warning on the switch statement says:
'constexpr QKeyCombination::operator int() const' is deprecated. Use QKeyCombination instead of int.
So I changed that line to this:
switch(key.toCombined())and that fixed that warning.
But, I still have warnings on the case statements with combined Key+Modifier.
I tried case (Qt::Key_A | Qt::ShiftModifier).tocombined(): but same warning.
I tried creating variables that I could use in the case statements (I have #include <QKeyCombination> at the top of the code):
QKeyCombination keyA_keyShift = QKeyCombination(Qt::Key_A,Qt::ShiftModifier); QKeyCombination keyS_keyShift = QKeyCombination(Qt::Key_S,Qt::ShiftModifier);But those gave errors indicating the constructor takes only one argument. Documentation clearly states it can take two, a Qt::Key or Qt::KeyboardModifiers in either order!
I asked Gemini for help and it suggested a code structure that looks like this:
auto combination = event->keyCombination(); switch (combination.toCombined()) { case (Qt::ControlModifier | Qt::Key_S).toCombined(): // Save action break; case (Qt::ControlModifier | Qt::Key_O).toCombined(): // Open action break; }But that does not work either, similar warnings.
I have tried using a series of if statements, but no help:
if (key.toCombined()==(Qt::Key_A | Qt::ShiftModifier)){ spdVal= (spdVal < 10 * ssss) ? 0.0 : (spdVal - 10 * ssss); } else if (key.toCombined()==(Qt::Key_S | Qt::ShiftModifier)){ spdVal+= 10 * ssss; }I am clearly missing something. Can anyone offer a fix?
