[Qt-interest] QStateMachine without MainWindow
Benjamin
bebl at mageta.org
Thu May 5 02:49:48 CEST 2011
Am 05.05.2011 00:00, schrieb emmanuel_mayssat at lynceantech.com:
> Hello,
>
> I am interested in the QStateMachine framework.
> I would like to run a statemachine in a terminal.
>
> Now I would like to generate QKeyEventTransition
> based on what I press on the keyboard.
>
> state_1 --[QEvent or Signal]--> state2
>
> How can I generate a QKeyEventTransition if I am not using a QMainWindow?
> In other words, how can I generate QEvents from my keyboard when using a terminal application?
>
> Thanks,
>
Quick and Dirty: extend the QCoreApplication-Methods exec() and event().
Before starting the main event-loop in your reimplemented exec (return
QCoreApplication::exec();) start a new thread which listens on stdin
(use c++ input-streams or extended Qt-streams; you also could go deeper
and use getchar() or even system-events if you know how to). Every time
the new threads gets a event on stdin, it should fire a signal which
contains the pressed key as QEvent and is connected to the reimplemented
event-slot in your extended QCoreApplication. This way, the pressed keys
should get queued through the qt-signal-slot system and you can process
them as you wish in your main thread.
I don't know of a "qt-way" to do this.. qt is still a "gui-framework" ;)
Also, under windows this way could be hard to go, 'cause stdin under
windows is a pain in the ass.. you _don't_ want to rely on it!
best regards,
- Ben
More information about the Qt-interest-old
mailing list