Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business

Forums

OverviewFelgo 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 10 years, 1 month ago by  Nuggetslug.
    #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
    Felgo 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.

Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded