Qprocess in real time in longer process
-
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 ? -
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 ?@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.
-
@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.
@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.
-
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 ?@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
gitprocess side. What makes you think that the output fromgitshould be immediately available to your calling process?I suspect that
gitoutputs something "funny" to achieve the update of the output as it counts up to 100%? For example, maybe it outputs with\rto "redraw" the progress lines? -
@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.
-
@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
gitprocess side. What makes you think that the output fromgitshould be immediately available to your calling process?I suspect that
gitoutputs something "funny" to achieve the update of the output as it counts up to 100%? For example, maybe it outputs with\rto "redraw" the progress lines?@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 -
@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 ?
ThanksThis post is deleted! -
@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 -
@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? -
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.