Unsolved start terminal with command by QProcess
-
@JonB sorry . i am not an expert in c++ nor qt.i am doing the job that my co-devloper should do .he is off-line and i can't sit back.
those code are copy past from many question /answers.
qt-forum is the help i can get now .
if you have anything that will work , it will be helpful.
-
@saber
This has nothing to do with C++. I am happy to help you but you will not say what it is you want to do. If you write earlieri want a specific terminal app will run the command.
why won't you say what the command is you want to run?
- Do you want to run an interactive terminal, and the user sits inside it, typing stuff, till he exits?
- Do you want the terminal to start, run some other command, and then exit?
- Or what?
Did you try what I suggested with
xterm
to see that that does open a terminal window, which I think you're saying your attempts do not? -
@JonB thanks.
i want the first one.
and i am trying the xterm way. -
@JonB i tried this
QProcess *Process = new QProcess(); QString exec = "xterm"; QStringList params; params <<"ls"; Process->start(exec,params);
-
@saber
That will not work.Please, you are simply answering inconsistently to each question I ask. I asked whether you want to run an interactive terminal the user sits in and types or whether you wish it to execute a command, to which you replied "i want the first one". But the example you give you are trying (incorrectly) to pass
ls
to it. Which is the second one.If & when you come back and clearly state what you actually wish to do I will answer. But while you say one thing and then try to do something quite different nobody can help you....
-
@JonB ok.
a pushbutton will open the terminal with the htop commnad(as it is the terminal app).
then a separate window will open which contains the terminal with running the htop app.
if user input command(ctrl +c) or the window close button clicked the window will close.(that's why i mean user will interact with the terminal by keyboard).in the command there will be other type of terminal app.
-
@saber
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 thexterm
, 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 htopQString l(QDir::homePath()); QProcess *process = new QProcess(); QString exec = "xterm"; QStringList params; params << "-hold" << "-e" << "htop" ; process->setWorkingDirectory(l); process->start(exec, params);
output
ther is now two things to do .
- extiting the command with the ctrl +c leave a empty window ,nothing in it.
- the command is running only in the xterm . i tried the xfce-terminal.i want all the known terminal should do this.
thanks
- extiting the command with the ctrl +c leave a empty window ,nothing in it.
-
@saber
If you do not want thexterm
to remain open for closure, remove the-hold
argument.If you want to use something other than
xterm
to run yourhtop
(or whatever), the whole point is that I had toman xterm
to discover that the way it runs a command for you is to specify-e <program> <argument> <argument>
. So if you wantxfce-terminal
instead ofxterm
, you will need to read its manual page to discover what command-line it takes. There will not be a generic "i want all the known terminal should do this", it will vary from terminal to terminal.BTW, if I had wanted to ask your question, now that I know what it is, I would have said something like:
"I want to run a program named
htop
fromQProcess
. However, the problem is that it needs a terminal window to display its output. How do I do that? And btw (for some reason) I'd like the terminal window to be provided byxfce-terminal
." -
@JonB in future i will take much time to clear the qustion.
now i thought it will be easy to open htop in other terminal and that will be universal.
because the htop app has a icon and when it clicked it opes the app in the defult terminal.
-
in future i will take much time to clear the qustion.
Thank you :)
because the htop app has a icon and when it clicked it opes the app in the defult terminal.
You misunderstand how "launching an app from an icon" works. This does not only apply to
htop
."Launching from an icon" under Linux is a feature of your Desktop Manager. And you could be using a variety of those under Linux, e.g. Unity, GNOME, I guess you're using XFCE. Almost certainly you have a
htop.desktop
file somewhere, probably hidden somewhere inside your user area (e.g. try runningfind ~ -name \*.desktop -print
; or it might be in either of/usr/share/applications
or~/.local/share/applications
). When the desktop launches from an icon it reads that file and that tells it what to do. And if you look in that file (it's text format) you''ll see something stating its a "console" or "terminal" application (e.g.Terminal=true
; also see how there is aExec=...
to specify what exactly it is to execute). So when your desktop launches it the desktop creates the console/terminal window for it to run in automatically. When we do it from within another application, like a Qt one, we need to do that ourselves explicitly, hence what you've been trying.