Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo


#172 it's not possibly to catch KEYCODE_BACK

alpha 4

Copied from http://code.google.com/p/android-lighthouse/issues/detail?id=78

Reported by spirit.qt.developer@gmail.com, May 26, 2011
What steps will reproduce the problem?
1. reimplement QWidget::keyPressEvent
2. try to catch KEYCODE_BACK pressing

What is the expected output? What do you see instead?
KEYCODE_BACK should be caught. The event goes to android framework.

What version of the product are you using? On what operating system?
latest sources from git. OS: Snow Leopard

Please provide any additional information below.
I noticed that there is a line in QTDIR/src/android/java/src/eu/licentia/necessitas/industrius/QtActivity.java
public boolean onKeyDown(int keyCode, KeyEvent event)
if (keyCode != KeyEvent.KEYCODE_BACK)
QtApplication.keyDown(keyCode, c, event.getMetaState());
return true;

Looks like this code breaks propagation KEYCODE_BACK to Qt.
I would test this by myself, but I can't find a place on a device where QtActivity.java is located.

Comment 1 by project member taipanro...@gmail.com, May 26, 2011
(No comment was entered for this change.)
Status: Accepted
Comment 2 by mawi...@gmail.com, Nov 18, 2011
I found out that the android back button triggers a close event in Qt. So all you have to do to catch this to implement your own handler.

I did this by implementing a class 'MyGraphicsView' derived from QGraphicsView where I re-implement the following method:

void MyGraphicsView::closeEvent(QCloseEvent pEvent)
Comment 3 by klochkov...@gmail.com, Nov 18, 2011
that's what I did after posting the issue.
Comment 4 by iza...@gmail.com, Jan 6, 2012
i also tried to re-implement 'closeEvent' but my app still exits when i hit the back key. this is my code:
void MobileApp::closeEvent(QCloseEvent
event){ //do somthing }

(mobile app exetends QDialog)
any idea?
Comment 5 by vordok.b...@gmail.com, Feb 9, 2012
I try the same at doesnt work


  • BogDan Vatra
    BogDan Vatra

    • status: accepted --> pending
    • milestone: unstable --> alpha 4
  • BogDan Vatra
    BogDan Vatra

    • status: pending --> closed