blackberry/Qt — Issue #8: Keyboard input occasionally fails for widgets with child widgets
Author: absmall
Created: 2011-11-27 23:20:29+00:00
State: open

This issue is somewhat intermittent - I have seen it appear and disappear with just whitespace changes to the code.

Compiling the program below, it should print a message to the console (or log file on playbook) on any keyboard input, this is what it does in linux. The qterm.h file contains includes of a few irrelevant headers - removing those irrelevant headers includes somehow makes it do this on playbook too (that is, without the includes, it works as I expect). But compiling the code exactly as-is, it does not print any message when the VKB is activated and a key is pressed on it. Adding prints to the Qt code, I can see that QWidget::setFocus() is called at some point on startup in the success case, and is not called in the failure case, but I haven't gotten further than that in debugging. If the 'new QPushButton(this) is commented out, then the problem never happens in my testing.

qterm.h:
#include
#include
#include
#include

class QTerm : public QWidget
{
Q_OBJECT
public:
QTerm(QWidget *parent = 0);
~QTerm( );

protected:
void keyPressEvent(QKeyEvent *);
};

qterm.cpp:
#include
#include
#include
#include
#include

QTerm::QTerm(QWidget *parent) : QWidget(parent)
{
new QPushButton(this);
}

QTerm::~QTerm()
{
}

void QTerm::keyPressEvent(QKeyEvent *event)
{
printf("Key %d pressed\n", event->key());
fprintf(stderr, "Key %d pressed\n", event->key());
}

int main(int argc, char *argv[])
{
QCoreApplication::addLibraryPath("app/native/lib");
QApplication app(argc, argv);

QTerm term(NULL);
term.show();

return app.exec();
}