Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Question about QProcess
Qt 6.11 is out! See what's new in the release blog

Question about QProcess

Scheduled Pinned Locked Moved Unsolved General and Desktop
18 Posts 6 Posters 5.7k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by A Former User
    #2

    Hi! Not sure what you mean. QProcess spawns processes, it's not a terminal emulator.

    1 Reply Last reply
    3
    • thamT Offline
      thamT Offline
      tham
      wrote on last edited by tham
      #3

      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).

      1 Reply Last reply
      2
      • RIVOPICOR RIVOPICO

        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.

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #4

        @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.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        RIVOPICOR 1 Reply Last reply
        1
        • jsulmJ jsulm

          @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.

          RIVOPICOR Offline
          RIVOPICOR Offline
          RIVOPICO
          wrote on last edited by RIVOPICO
          #5

          @jsulm @jsulm For example i can do easy commands in linux like .. process1.start("ls"); .. But when i use cd .. for example all time show me the same path why?

          1 Reply Last reply
          0
          • p3c0P Offline
            p3c0P Offline
            p3c0
            Moderators
            wrote on last edited by p3c0
            #6

            @RIVOPICO QProcess just fires the command and forgets. It wont remember the earlier state. So if you cd to previous directory in one QProcess and then do ls in the next QProcess, dont expect it to show contents from previous directory. It will always display the contents in same directory.

            157

            RIVOPICOR 1 Reply Last reply
            2
            • p3c0P p3c0

              @RIVOPICO QProcess just fires the command and forgets. It wont remember the earlier state. So if you cd to previous directory in one QProcess and then do ls in the next QProcess, dont expect it to show contents from previous directory. It will always display the contents in same directory.

              RIVOPICOR Offline
              RIVOPICOR Offline
              RIVOPICO
              wrote on last edited by
              #7

              @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...

              1 Reply Last reply
              0
              • p3c0P Offline
                p3c0P Offline
                p3c0
                Moderators
                wrote on last edited by
                #8

                @RIVOPICO Are you trying to emulate QDir through QProcess ?
                QDir already contains cd .. and file listing is done through QDirIterator.

                157

                RIVOPICOR 1 Reply Last reply
                1
                • p3c0P p3c0

                  @RIVOPICO Are you trying to emulate QDir through QProcess ?
                  QDir already contains cd .. and file listing is done through QDirIterator.

                  RIVOPICOR Offline
                  RIVOPICOR Offline
                  RIVOPICO
                  wrote on last edited by
                  #9

                  @p3c0 said in Question about QProcess:

                  QDirIterator.

                  i tried too but qprocess show me all time the same path.

                  1 Reply Last reply
                  0
                  • p3c0P Offline
                    p3c0P Offline
                    p3c0
                    Moderators
                    wrote on last edited by
                    #10

                    @RIVOPICO QDirIterator is not a process so cant be used with QProcess. 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 using cd and ls and QProcess ? Also what your application is supposed to do ?

                    157

                    RIVOPICOR 1 Reply Last reply
                    1
                    • p3c0P p3c0

                      @RIVOPICO QDirIterator is not a process so cant be used with QProcess. 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 using cd and ls and QProcess ? Also what your application is supposed to do ?

                      RIVOPICOR Offline
                      RIVOPICOR Offline
                      RIVOPICO
                      wrote on last edited by RIVOPICO
                      #11

                      @p3c0 I am trying to simulate one terminal with simple application in qt for linux nothing more.

                      p3c0P 1 Reply Last reply
                      0
                      • VRoninV Offline
                        VRoninV Offline
                        VRonin
                        wrote on last edited by VRonin
                        #12

                        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

                        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                        ~Napoleon Bonaparte

                        On a crusade to banish setIndexWidget() from the holy land of Qt

                        RIVOPICOR 1 Reply Last reply
                        2
                        • RIVOPICOR RIVOPICO

                          @p3c0 I am trying to simulate one terminal with simple application in qt for linux nothing more.

                          p3c0P Offline
                          p3c0P Offline
                          p3c0
                          Moderators
                          wrote on last edited by
                          #13

                          @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.

                          157

                          RIVOPICOR 1 Reply Last reply
                          2
                          • p3c0P p3c0

                            @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.

                            RIVOPICOR Offline
                            RIVOPICOR Offline
                            RIVOPICO
                            wrote on last edited by
                            #14

                            @p3c0 setWorkingDirectory i can change the path. But i think will not be remembered..

                            1 Reply Last reply
                            0
                            • VRoninV VRonin

                              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

                              RIVOPICOR Offline
                              RIVOPICOR Offline
                              RIVOPICO
                              wrote on last edited by
                              #15

                              @VRonin you say send the commands but for example if i change the path will be remembered?

                              thamT 1 Reply Last reply
                              0
                              • RIVOPICOR RIVOPICO

                                @VRonin you say send the commands but for example if i change the path will be remembered?

                                thamT Offline
                                thamT Offline
                                tham
                                wrote on last edited by tham
                                #16

                                @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();
                                
                                RIVOPICOR 2 Replies Last reply
                                1
                                • thamT tham

                                  @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();
                                  
                                  RIVOPICOR Offline
                                  RIVOPICOR Offline
                                  RIVOPICO
                                  wrote on last edited by
                                  #17
                                  This post is deleted!
                                  1 Reply Last reply
                                  0
                                  • thamT tham

                                    @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();
                                    
                                    RIVOPICOR Offline
                                    RIVOPICOR Offline
                                    RIVOPICO
                                    wrote on last edited by
                                    #18

                                    @tham you are right it's nice idea

                                    1 Reply Last reply
                                    0

                                    • Login

                                    • Login or register to search.
                                    • First post
                                      Last post
                                    0
                                    • Categories
                                    • Recent
                                    • Tags
                                    • Popular
                                    • Users
                                    • Groups
                                    • Search
                                    • Get Qt Extensions
                                    • Unsolved