Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Qml on Android and back button
Forum Updated to NodeBB v4.3 + New Features

Qml on Android and back button

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 2.2k 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.
  • deleted57D Offline
    deleted57D Offline
    deleted57
    wrote on last edited by
    #1

    Hi all
    I'm new to qml programming. I'm developing an android app using qml and I'm facing the problem to intercept android back button for avoid to have my app closed in some point where should not. Looking into documentation the solution seem easy. Using the Keys.onPressed event into a focused item (focus: true) and manage the pression. This solution work with a simple app but in an qml app having a lot of buttons the focus continuosly change between controls based to the actions of user and the initial focused item with the code for manage the back button key, once lost the focus, doesn't work anymore as obvious. I guess is not a good solution to "clone" the code managin keys to all the items, I'm sure it should be another solution, but which? Is there a way to have a "main" keyboard manager able to get the key event before forwarded to child items in qml? This for have a unique code. I can not make it from C++ side since I need to have an ApplicationWindow than I need to use the QQmlApplicationEngine object. Another solution could be to "force" focus to stay in a specific item, is possible?
    Thank you the help

    1 Reply Last reply
    0
    • L Offline
      L Offline
      luca
      wrote on last edited by luca
      #2

      Hi,
      have you tried:

      ApplicationWindow {
      ...
      onClosing: {
      
              if(YOUR_CLOSE_CONDITION){
                  close.accepted = false
              }
          }
         .....
      }
      
      1 Reply Last reply
      0
      • deleted57D Offline
        deleted57D Offline
        deleted57
        wrote on last edited by
        #3

        Hi
        Thank you for your reply. I just found the same solution once discovered how android manage the back button key. I agree this is the only way to ensure to get the event always maanaged in the same code point.
        Thank you again for your help anyway.

        1 Reply Last reply
        0

        • Login

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