PDA

View Full Version : Problems with very simple keyPressEvent in MainWindow



naizarak
28th April 2013, 21:35
Hello

I've been trying to add a basic keyboard input handler to my mainwindow. The mainwindow has a few Qlabels and pushbuttons, nothing fancy.

I've tried adding the following code:

mainwindow.h

protected:
void keyPressEvent(QKeyEvent *event);

mainwindow.cpp

void MainWindow::keyPressEvent(QKeyEvent *event)
{
std::cout << "pressed";
}

But nothing happens when I press a key. I think there's something very simple that I'm missing, but I just can't figure it out. Trust me I've googled quite a bit on the topic but got nowhere. Any help would be greatly appreciated. Thanks.

saman_artorious
29th April 2013, 07:56
mainwindow.cpp

void MainWindow::keyPressEvent(QKeyEvent *event)
{
std::cout << "pressed";
}


remove std::cout.


#include <QDebug>
qDebug() << "pressed";