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. Qprocess in real time in longer process
Qt 6.11 is out! See what's new in the release blog

Qprocess in real time in longer process

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 5 Posters 1.2k Views 1 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.
  • M Offline
    M Offline
    Marioz
    wrote on last edited by
    #1

    Hello ,
    I need to make a tool that clones a repo .
    In order to keep track of what's going on and report to the user , I need to read the responses in real time .

    void content::download(){
        p = new QProcess( this );
     connect (p, SIGNAL(readyReadStandardOutput()), this, SLOT(readData()));
     connect (p, SIGNAL(readyReadStandardError()), this, SLOT(errorData())); 
    
          p->setWorkingDirectory("C:\\Users\\Mario\\Desktop");
          p->start("git", QStringList() << "clone"<<"repo");
    
    }
    void content::readData(){
        log_box->append( p->readAllStandardOutput() );
    }
    void content::errorData(){
        log_box->append( p->readAllStandardError() );
    }
    

    The repo gets cloned successfully , but only the very first response "Cloning into 'repo'..." gets printed .
    When I run the same command in cmd it "later" adds : remote: Enumerating objects: 54, done.
    remote: Counting objects: 100% (54/54), done.
    remote: Compressing objects: 100% (50/50), done.
    remote: Total 54 (delta 8), reused 0 (delta 0), pack-reused 0
    Receiving objects: 100% (54/54), 21.03 MiB | 1.81 MiB/s, done.
    Resolving deltas: 100% (8/8), done.
    Is that a flushing problem or something else ?

    JoeCFDJ JonBJ 2 Replies Last reply
    0
    • M Marioz

      Hello ,
      I need to make a tool that clones a repo .
      In order to keep track of what's going on and report to the user , I need to read the responses in real time .

      void content::download(){
          p = new QProcess( this );
       connect (p, SIGNAL(readyReadStandardOutput()), this, SLOT(readData()));
       connect (p, SIGNAL(readyReadStandardError()), this, SLOT(errorData())); 
      
            p->setWorkingDirectory("C:\\Users\\Mario\\Desktop");
            p->start("git", QStringList() << "clone"<<"repo");
      
      }
      void content::readData(){
          log_box->append( p->readAllStandardOutput() );
      }
      void content::errorData(){
          log_box->append( p->readAllStandardError() );
      }
      

      The repo gets cloned successfully , but only the very first response "Cloning into 'repo'..." gets printed .
      When I run the same command in cmd it "later" adds : remote: Enumerating objects: 54, done.
      remote: Counting objects: 100% (54/54), done.
      remote: Compressing objects: 100% (50/50), done.
      remote: Total 54 (delta 8), reused 0 (delta 0), pack-reused 0
      Receiving objects: 100% (54/54), 21.03 MiB | 1.81 MiB/s, done.
      Resolving deltas: 100% (8/8), done.
      Is that a flushing problem or something else ?

      JoeCFDJ Offline
      JoeCFDJ Offline
      JoeCFD
      wrote on last edited by JoeCFD
      #2

      @Marioz said in Qprocess in real time in longer process:

      void content::download(){
      p = new QProcess( this );
      connect (p, SIGNAL(readyReadStandardOutput()), this, SLOT(readData()));
      connect (p, SIGNAL(readyReadStandardError()), this, SLOT(errorData()));

        p->setWorkingDirectory("C:\\Users\\Mario\\Desktop");
        p->start("git", QStringList() << "clone"<<"repo");
      

      }

      if it is long, put it into a thread. Otherwise, GUI will be frozen.

      jsulmJ 1 Reply Last reply
      0
      • JoeCFDJ JoeCFD

        @Marioz said in Qprocess in real time in longer process:

        void content::download(){
        p = new QProcess( this );
        connect (p, SIGNAL(readyReadStandardOutput()), this, SLOT(readData()));
        connect (p, SIGNAL(readyReadStandardError()), this, SLOT(errorData()));

          p->setWorkingDirectory("C:\\Users\\Mario\\Desktop");
          p->start("git", QStringList() << "clone"<<"repo");
        

        }

        if it is long, put it into a thread. Otherwise, GUI will be frozen.

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

        @JoeCFD said in Qprocess in real time in longer process:

        Otherwise, GUI will be frozen

        Only when using https://doc.qt.io/qt-6/qprocess.html#waitForFinished, otherwise QProcess is assynchronous, no need for threads.

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

        M 1 Reply Last reply
        3
        • M Marioz

          Hello ,
          I need to make a tool that clones a repo .
          In order to keep track of what's going on and report to the user , I need to read the responses in real time .

          void content::download(){
              p = new QProcess( this );
           connect (p, SIGNAL(readyReadStandardOutput()), this, SLOT(readData()));
           connect (p, SIGNAL(readyReadStandardError()), this, SLOT(errorData())); 
          
                p->setWorkingDirectory("C:\\Users\\Mario\\Desktop");
                p->start("git", QStringList() << "clone"<<"repo");
          
          }
          void content::readData(){
              log_box->append( p->readAllStandardOutput() );
          }
          void content::errorData(){
              log_box->append( p->readAllStandardError() );
          }
          

          The repo gets cloned successfully , but only the very first response "Cloning into 'repo'..." gets printed .
          When I run the same command in cmd it "later" adds : remote: Enumerating objects: 54, done.
          remote: Counting objects: 100% (54/54), done.
          remote: Compressing objects: 100% (50/50), done.
          remote: Total 54 (delta 8), reused 0 (delta 0), pack-reused 0
          Receiving objects: 100% (54/54), 21.03 MiB | 1.81 MiB/s, done.
          Resolving deltas: 100% (8/8), done.
          Is that a flushing problem or something else ?

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @Marioz said in Qprocess in real time in longer process:

          Is that a flushing problem or something else ?

          It looks like output is being buffered at the git process side. What makes you think that the output from git should be immediately available to your calling process?

          I suspect that git outputs something "funny" to achieve the update of the output as it counts up to 100%? For example, maybe it outputs with \r to "redraw" the progress lines?

          M 1 Reply Last reply
          0
          • jsulmJ jsulm

            @JoeCFD said in Qprocess in real time in longer process:

            Otherwise, GUI will be frozen

            Only when using https://doc.qt.io/qt-6/qprocess.html#waitForFinished, otherwise QProcess is assynchronous, no need for threads.

            M Offline
            M Offline
            Marioz
            wrote on last edited by
            #5

            @jsulm Yep , that's right .. it doesn't get frozen

            1 Reply Last reply
            0
            • JonBJ JonB

              @Marioz said in Qprocess in real time in longer process:

              Is that a flushing problem or something else ?

              It looks like output is being buffered at the git process side. What makes you think that the output from git should be immediately available to your calling process?

              I suspect that git outputs something "funny" to achieve the update of the output as it counts up to 100%? For example, maybe it outputs with \r to "redraw" the progress lines?

              M Offline
              M Offline
              Marioz
              wrote on last edited by
              #6

              @JonB Thanks for your reply .
              It's not "immediately" available but that's not the problem . The problem is that it's never available idk .Even when the cloning is done it doesn't show anything .
              Can you think of anyway I could check what's the output ? or different approaches I may try ?
              Thanks

              Kent-DorfmanK JonBJ 2 Replies Last reply
              0
              • M Marioz

                @JonB Thanks for your reply .
                It's not "immediately" available but that's not the problem . The problem is that it's never available idk .Even when the cloning is done it doesn't show anything .
                Can you think of anyway I could check what's the output ? or different approaches I may try ?
                Thanks

                Kent-DorfmanK Offline
                Kent-DorfmanK Offline
                Kent-Dorfman
                wrote on last edited by
                #7
                This post is deleted!
                1 Reply Last reply
                0
                • M Marioz

                  @JonB Thanks for your reply .
                  It's not "immediately" available but that's not the problem . The problem is that it's never available idk .Even when the cloning is done it doesn't show anything .
                  Can you think of anyway I could check what's the output ? or different approaches I may try ?
                  Thanks

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by
                  #8

                  @Marioz
                  You need to be specific. Are you saying you do not get any output, you only get output at the end or very notably are you saying the command does not run at all?

                  M 1 Reply Last reply
                  0
                  • JonBJ JonB

                    @Marioz
                    You need to be specific. Are you saying you do not get any output, you only get output at the end or very notably are you saying the command does not run at all?

                    M Offline
                    M Offline
                    Marioz
                    wrote on last edited by
                    #9

                    @JonB
                    I only get the rest when I'm using CMD .. not in qt

                    1 Reply Last reply
                    0
                    • Kent-DorfmanK Offline
                      Kent-DorfmanK Offline
                      Kent-Dorfman
                      wrote on last edited by
                      #10

                      https://www.informit.com/articles/article.aspx?p=1405549&seqNum=5

                      It is from Qt4 but the I believe the concepts are still relevant.

                      as for git clone command...will depend on how it is written? is output to stdout or stderr? has the author embedded ANSI output controls in the output strings?

                      and for what it's worth, the answer to your question/problem is in the manpage for git clone.

                      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