PDA

View Full Version : read stdout with QProcess under Windows



jlbrd
1st September 2006, 15:41
Hi,
In QIde I use ctags to populate a combo with methods of a file. I use an option of ctags "-f-" who write the result of the parsing to stdout. Then I read stdout to parse the result. The code work fine under Linux. Under Windows nothing is read and lu.isEmpty() return true. ctags is a solid tool and I requests what does not work under Windows.


QProcess *testCtags = new QProcess();
testCtags->start("ctags", QStringList()<<"-f-" << "--fields=+S+K+n" << filename());
testCtags->waitForFinished(5000);
QString lu = testCtags->readAll();
if( !lu.isEmpty() )
{
foreach(QString s, lu.split("\n") )
{
...
}
}

Note : If I use connect for readyReadStandardError or readyReadStandardOutput signals the slot is never called.
Thanks

nouknouk
1st September 2006, 15:55
Hi Jean Luc,

maybe you should test the return value of waitForFinished() and just before test the return value of waitForStarted(). If one of them returns false it may be useful for better understanding the issue.

jlbrd
1st September 2006, 16:07
I think not because if I connect readyReadStandardError or readyReadStandardOutput to a slot, this slot it's never called. If I use connect I don't delete the process by delete. Thus not problem of waiting. But never works!


testCtags = new QProcess();
connect(testCtags, SIGNAL(readyReadStandardError()), this, SLOT(slotLoadCtags()) );
connect(testCtags, SIGNAL(readyReadStandardOutput()), this, SLOT(slotLoadCtags()) );
testCtags->start("ctags", QStringList()<<"-f-" << "--fields=+S+K+n" << filename());
...
//
void Editor::slotLoadCtags()
{
QString lu = testCtags->readAllStandardOutput();
...
testCtags->deleteLater();
...

jlbrd
1st September 2006, 16:52
Well, I created this program who wrote to stdout on Windows:


#include <stdio.h>
int main(int argc, char *argv[])
{
fprintf(stdout, "Test line\n");
fflush( stdout );
}

then I replaced ctags by stdout.exe in QProcess::start and... It's work. Thus it's ctags who don't works and not QProcess.
End of my requests for QProcess. Now it is necessary to make work ctags!
thanks

jlbrd
1st September 2006, 18:29
In fact and after have finding, ctags works well with "-f-" to write to stdout. It's not my day, it's all!