PDA

View Full Version : keyPressEvent don't work



robel
8th September 2015, 22:43
Hi,
i have problem with keypressed
to test my keypressed i put


void myapp::keyPressEvent(QKeyEvent* evt)
{

if (Qt::Key_Up)

{
cout<<"i winnnnn";
add_object();

emit keyPress(evt);}
}
but even if i press another key(z,y,left...) i see "i winn" in the screen and the "add_object() method executed too

Grzyboo
8th September 2015, 23:13
Think for a second. What the hell is this if statement?

if(Qt::Key_Up)
it's literally

if(0x01000013)
so always true.

You surely meant

if(evt.key() == Qt::Key_Up)

robel
9th September 2015, 07:56
It wrk thank you