What is the recommended way of passing keyboad events to QProcess transparently?
I have a GUI application, which creates a QProcess
inside, catches its output and shows it on a form. I need to somehow catch key events from the form to pass them to QProcess
(to make it fell as close as possible to real terminal window).
So, I suppose, I should process keyReleaseEvent()
and somehow transform either event.text()
(which is QString
) or event.key()
(which is int
) to argument, suitable for process.write()
(which takes char*
or QByteArray
). Is there some recommended 开发者_开发百科way to do such a conversion (taking into account localization issues, ctrl/alt/shift modifiers and so on)? I do not really want to construct some sort of mapping from key()
return values to char*
strings; and text()
drops modifiers.
Moreover, if I start process with command bash -c sudo something
in QProcess, it exits instantly, complaining that "no tty present and no askpass program specified", so I may be doing something completely wrong...
The problem is more than just deciding what to write to the process.
You can't emulate a terminal just by reading/writing stdout/stdin of a process, it's more complicated than that. Think about the program less
, or any pager, for example. How does it know how many lines to print at a time? It needs information about the terminal which isn't represented through stdin/stdout/stderr.
Emulating a terminal is beyond the scope of QProcess. If you're really sure you need to do this then use some existing Qt-based terminal emulator as a starting point (e.g. Konsole).
精彩评论