[Qt-interest] QStateMachine without MainWindow
Benjamin
bebl at mageta.org
Thu May 5 04:20:18 CEST 2011
Am 05.05.2011 02:49, schrieb Benjamin:
> 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.
Well, I thought a little about it and it might be hard to get exactly
what you want (the "every time the new thread gets a event on
stdin"-part). Doing a simple cin.getchar or getchar might not be enough
to react without pressing return or some "action-key" depending on your
platform (linux, windows, macos..).
To react on every single key-stroke in your terminal you would have to
do a little "dirty" work and interact with your specific platform. On
Linux/Unix you could use functions from curses.h (look at getch()) or
termios.h (deactivate the canonical mode of stdin and again use
getchar()).. but I highly doubt that this would work under windows. I
don't usually program terminal-application under windows.. so maybe you
have to google a little for the windows-way to get what you want (if
there is any :D.. I think most windows-users would freak-out if they
would have to interact with a shell).
best regards,
- Ben
More information about the Qt-interest-old
mailing list