Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Warnings for QKeyCombination deprecation after Qt6
Forum Updated to NodeBB v4.3 + New Features

Warnings for QKeyCombination deprecation after Qt6

Scheduled Pinned Locked Moved Solved General and Desktop
deprecatedqkeycombination
6 Posts 3 Posters 371 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    just-ero
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • J Offline
      J Offline
      just-ero
      wrote on last edited by
      #6

      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 in QKeyCombination | Qt::ALT, which is what's raising the warning, since QKeyCombination 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 in Qt::Modifiers | Qt::Key_R, which is an operation that is defined.

      This is kinda the answer I was looking for.

      1 Reply Last reply
      1
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #2

        See https://doc.qt.io/qt-6/qkeycombination.html#QKeyCombination-1

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        J 1 Reply Last reply
        0
        • Christian EhrlicherC Christian Ehrlicher

          See https://doc.qt.io/qt-6/qkeycombination.html#QKeyCombination-1

          J Offline
          J Offline
          just-ero
          wrote on last edited by just-ero
          #3

          @Christian-Ehrlicher
          I would not be making this post if I understood what that page is telling me.

          JonBJ 1 Reply Last reply
          0
          • J just-ero

            @Christian-Ehrlicher
            I would not be making this post if I understood what that page is telling me.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #4

            @just-ero
            I have not used this, but isn't @Christian-Ehrlicher telling you from the linked method to keep the modifiers separate from the key? So:

            QKeyCombination(Qt::CTRL | Qt::ALT, Qt::Key_R)
            

            ?

            1 Reply Last reply
            0
            • Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #5

              Just use this ctor and pass your key and modifiers - what else to say?

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply
              0
              • J Offline
                J Offline
                just-ero
                wrote on last edited by
                #6

                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 in QKeyCombination | Qt::ALT, which is what's raising the warning, since QKeyCombination 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 in Qt::Modifiers | Qt::Key_R, which is an operation that is defined.

                This is kinda the answer I was looking for.

                1 Reply Last reply
                1
                • J just-ero has marked this topic as solved on

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved