keypressed and keyreleased
-
@genli create QKeyEvent and post it to the event queue https://doc.qt.io/qt-5/qcoreapplication.html#postEvent
I think the above is overly complicated though. I'd go with a set of flags, either standalone or the vector of bool, and custom signal - let's say
keyboardStateChanged()
or something.
In keypressed/keyreleased events you just set the flag and emit the signal.
The signal it self connected as a queued connection, so it's just processed after the control returns from the keyboard event processing, connected to the slot which in turn, sends movement commands to the remote.
Less methods, less code the way I see it, clearer approach.EDIT: also, try do debug key events to see possible modifiers from the event. Those are platform dependent.
-
@genli
You have several ways to do this, depend on own style, as it often happens there isn't only one way to do something.There's a way to do it with signal and slot ?
Yes of course!
As @artwaw says you can use event filter.
I wouldn't use eventFiler, but not because is not correct, but only because it is not my style, doesn't mean that my style is the best way!The @artwaw's tip is good, in short, think simple, less code you have less bug you will have.
My tip is the same, having one point where you manage the moving. How you send the variable, flags, and so on depends only on you and how the project is designed.
Normally in my projects, I like to have an application core manager that is independent of UI. The UI and the core communicate between them via signals.
But before going ahead, for me, you must understand because you have:
Forward
keyReleased
when wouldn't be so.