Command terminal using QTextEdit
-
Hi,
I am trying to create a terminal kind of interface using QTextEdit by which i would like to execute commands on standard input terminal.
I have a way to send the command from Qt app to standard input.
now my tasks are-
setting up a command promt
ex:
@
Prompt>
@ -
After every return and enter press new prompt has to be shown.
-
cursor should always wait at Prompt > and not move back from Prompt> when i press backspace , though i should be able to remove the other chars when i type(this is really needed)
following the code i am using to achieve the same, except the 3 point.
Initially
@ cmd->append("Pmt>"); @@
void read(QString str)
{
static int nline =0;
QStringList lines = str.split("\n");
QString line = lines[nline];
QByteArray ba = line.toLocal8bit();
char *tstr = ba.data();
cout<<tstr<<endl;
nline++;
cmd->append("Pmt>");
}
@@
bool eventFilter(QObject (obj, QEvent *eve)
{
if(eve->type()==QEvent::KeyPress){
QKeyEvent keve = static_cast<QKeyEvent>(eve);
if( keve->key()==Qt::Key_Return ||
keve->key()==Qt::Key_Enter ) {
str = cmd->toPlaintText();
read(str);
} else {
keve->accept();
str = cmd->toPlainText();
}
}else {
return QObject::evenFilter(obj,eve);
}
}
@problems i am facing:
-
cursor is waiting below the promt after entering the first command ex.
@
Prompt>
|
@ -
The Promt> is getting erased by when i use backspace(need help here)
-
-
Hey, I've once done such a component. Here's the code, maybe you can steal something useful :)
qpconsole.h: http://pastebin.com/0tN70DqE
qpconsole.cpp: http://pastebin.com/D9UCPsVEIf a command is entered, the signal command(QString, QStringList) is emitted, where the QString is the command and QStringList the (optional) parameters. Use the print(QString) function to output something on the console. If a prompt shall be printed where the user may enter a new command, call prepareCommandLine()