Unsolved Question about QProcess
-
I was checking about qprocess class to learn more about process in Qt. But i have one question why qprocess créate all time new console so for example you are doing one thing with qprocess and you need repeat the previous thing again to complete the same thing. I dont know if i explained very well. thx in advance. I am trying to do one terminal for Linux.
-
Hi! Not sure what you mean. QProcess spawns processes, it's not a terminal emulator.
-
Not sure what you mean either. As Wieland mentioned, QProcess is use to spawn process and communicate with the process(give arguments, read output, write input etc).
If you want to create a terminal tool(simple CLI tool), what you need is QCommandLineParser. I use it to create a simple CLI tool to compress/decompress files and folders(QCompressor).
-
@RIVOPICO What exactly do you start using QProcess? If it is something like "cmd.exe ..." then you will get a console, but that's nothing related to Qt/QProcess - it's you starting a new console via QProcess.
And yes your explanation is really unclear - at least you should say what you're starting using QProcess. -
-
@RIVOPICO
QProcess
just fires the command and forgets. It wont remember the earlier state. So if youcd
to previous directory in oneQProcess
and then dols
in the nextQProcess
, dont expect it to show contents from previous directory. It will always display the contents in same directory. -
@p3c0 But when i do this say me this message:
Two pointers can't be added at the same time and the other thing is that qprocess all time create me a new console so i couldn't remember what i did before it's only this the problem... -
@RIVOPICO Are you trying to emulate
QDir
throughQProcess
?
QDir
already contains cd .. and file listing is done through QDirIterator. -
@p3c0 said in Question about QProcess:
QDirIterator.
i tried too but qprocess show me all time the same path.
-
@RIVOPICO
QDirIterator
is not a process so cant be used withQProcess
. I was just suggesting an alternate way for what I imagined you are trying to do.
Can you explain again what you are trying to do usingcd
andls
andQProcess
? Also what your application is supposed to do ? -
@p3c0 I am trying to simulate one terminal with simple application in qt for linux nothing more.
-
If I'm not mistaken you just need to start the terminal with QProcess and then use QProcess::write to send the commands. see the gzip example in http://doc.qt.io/qt-5/qprocess.html
-
@RIVOPICO said in Question about QProcess:
@p3c0 I am trying to simulate one terminal with simple application in qt for linux nothing more.
Then IMO
QProcess
is not the right way to do. May be you should try using some library like for eg. libvte.
Found this QML based term emulator. -
@p3c0 setWorkingDirectory i can change the path. But i think will not be remembered..
-
@VRonin you say send the commands but for example if i change the path will be remembered?
-
@RIVOPICO you can record the path by yourself, stack or vector sounds like a good data structure for this purpose(stack is an adapter in stl, either vector,deque or list work for std::stack).
Following is the idea of how to store the path you iterate, please handle the errors and convert it to nice,
reuse able function by yourself.//store the paths you iterate std::vector<QString> paths; paths.emplace_back("first path"); paths.emplace_back("second path"); if(input_path == "cd"){ QDir new_path(paths.back()); new_path.cd(); paths.emplace_back(new_path.absolutePath()); } //back to previous path, stl split back and pop_back to two actions for the sake of exception safe auto const path = paths.back(); paths.pop_back();
-
This post is deleted! -
@tham you are right it's nice idea