Forums

OverviewV-Play 1 Support › Trouble implementing Android back button

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #6865

    Andrew

    I’ve been following the Chicken Outbreak Demo as a reference. I have a SceneBase that contains

    ...
    signal backPressed
    
    Keys.onPressed:{
      console.debug("SceneBase: pressed key code: ", event.key)
    
      if(event.key === Qt.Key_Backspace && system.desktopPlatform) {
      console.debug("backspace key pressed - simulate a back key pressed on desktop platforms for debugging the user flow of 
          Android on windows!")
                backPressed()
      }
    }
    
    Keys.onBackPressed: {
      backPressed()
    }
    ...

    Which is the same code used in the Chicken Outbreak SceneBase.qml

     

    In their MainScene.qml, they have the onBackPressed function and a Connections which prompts the user if they really want to quit. Although I personally wouldn’t want a prompt, I just copied and pasted it and all I got was the debug info “wm_char received for wparam: 8” each time I pressed backspace. So, thinking it had to do with activeScene (the target of their Connections) I tried simply adding a function in my main scene as follows

    onBackPressed: {
      Qt.quit()
    }

    and I still only get the debug info “wm_char received for wparam: 8”.

     

    Edit: When I run the Chicken Outbreak Demo, the backspace functionality works on that program.

    • This topic was modified 4 years, 9 months ago.
    #6867

    Andrew

    RESOLVED. I was tinkering around and found out what I needed to do. In my main.qml I added

    onStateChanged: {
      if (state === "main")
        activeScene = startScene //startScene is the id of the scene you wish to implement back functionality.
    }

     

    In my StartScene.qml I added

    Connections{
      target: activeScene
      onBackPressed: {
        Qt.quit()
      }
    }

    As I am a beginner in app development and v-play, I just modified the template code using the Connections item, although I am not sure if this is an effective way to do it (it does work, however). I hope this helps somebody out! I had to reply because I hate when searching forum posts that have my same problem and just end with “lol nevermind” and leave me hanging.

    #6892

    Christian
    V-Play Team

    Hi,

    thanks for posting the solution you found!

    For the key simulation to work on desktop, you indeed need to change the activeScene to the currently active scene, because only then the keyboard focus is handled correctly.

    Cheers, Chris

Viewing 3 posts - 1 through 3 (of 3 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Voted #1 for:

  • Easiest to learn
  • Most time saving
  • Best support

Develop Cross-Platform Apps and Games 50% Faster!

  • Voted the best supported, most time-saving and easiest to learn cross-platform development tool
  • Based on the Qt framework, with native performance and appearance on all platforms including iOS and Android
  • Offers a variety of plugins to monetize, analyze and engage users
FREE!
create apps
create games
cross platform
native performance
3rd party services
game network
multiplayer
level editor
easiest to learn
biggest time saving
best support