关键:
QString exec = "xterm"; //选择终端
QStringList params; //****** 这是关键:在输入终端中,输入的参数流 ******
params << "-hold" << "-e" << "ls" << "-l"; // 不同的终端,一般参数也不相同。
You still don't state what it is you want to happen in the terminal, I'm tearing my hair out! Does it sit there interactively doing nothing waiting for the user to type some commands, or does it run some command (which you won't tell us about), show its output, leave the window there awaitng you to only close it, and that's it?
Using xterm I'll show you both of these:
Sits interactively:
QProcess *process =new QProcess();
QString exec= "xterm";
process->start(exec);
Runs ls -l, output in the xterm, does not accept any further commands, leaves window open, user can close window:
QProcess *process = new QProcess();
QString exec = "xterm"; //选择终端
QStringList params; //****** 这是关键:在输入终端中,输入的参数流 ******
params << "-hold" << "-e" << "ls" << "-l"; // 不同的终端,一般参数也不相同。
process->start(exec, params);
When one of these does whatever you want we might be getting somewhere....?
@JonB i want the second one .
just open the terminal with the commnad and sit there .
here is the code for htop
QString l(QDir::homePath());
QProcess *process = new QProcess();
QString exec = "xterm";
QStringList params;
params << "-hold" << "-e" << "htop" ;
process->setWorkingDirectory(l);
process->start(exec, params);
start terminal with command by QProcess
https://forum.qt.io/topic/93735/start-terminal-with-command-by-qprocess/17