Question about QProcess
-
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).
-
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.
@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 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
QProcessjust fires the command and forgets. It wont remember the earlier state. So if youcdto previous directory in oneQProcessand then dolsin the nextQProcess, dont expect it to show contents from previous directory. It will always display the contents in same directory. -
@RIVOPICO
QProcessjust fires the command and forgets. It wont remember the earlier state. So if youcdto previous directory in oneQProcessand then dolsin the nextQProcess, dont expect it to show contents from previous directory. It will always display the contents in same directory. -
@RIVOPICO Are you trying to emulate
QDirthroughQProcess?
QDiralready contains cd .. and file listing is done through QDirIterator. -
@RIVOPICO Are you trying to emulate
QDirthroughQProcess?
QDiralready contains cd .. and file listing is done through QDirIterator. -
@RIVOPICO
QDirIteratoris 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 usingcdandlsandQProcess? Also what your application is supposed to do ? -
@RIVOPICO
QDirIteratoris 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 usingcdandlsandQProcess? Also what your application is supposed to do ? -
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
-
@p3c0 I am trying to simulate one terminal with simple application in qt for linux nothing more.
@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
QProcessis not the right way to do. May be you should try using some library like for eg. libvte.
Found this QML based term emulator. -
@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
QProcessis not the right way to do. May be you should try using some library like for eg. libvte.
Found this QML based term emulator. -
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
-
@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(); -
@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(); -
@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();