c++ - How to read updating text file with Qt? -


i have 1 application(i dont have source code), prints output console. writing output file like;

./otherapp > out.txt 

and c++ qt programming, writing application should read output simultaneously. code reading out.txt file created. mean while otherapp continue write output, if project finished reading, not reading rest of output file.

here usual method qtextstream reading output.

qstring filename = "/.1/work/appoutput/out1";  qfile inputfile(filename); if(inputfile.open(qiodevice::readonly)) {     qtextstream in(&inputfile);     while(!in.atend())     {         qstring line = in.readline();          qdebug() << line;     }     inputfile.close(); } 

my question how can read out text file until close otherapp or after not write inside?

edit:

thanks @bowdzone changed code , working. here code.

    qstring program = "/.1/work/otherapp";     qstringlist arguments;     arguments << "-x" <<  "1002";      qprocess *myprocess = new qprocess();     myprocess->start(program, arguments);      qstring strout = myprocess->readallstandardoutput();      qdebug() << qtime::currenttime().tostring() << strout;      myprocess->waitforfinished(); 

however qdebug() not show output of otherapp there log in application. looks myprocess->waitforfinished() should not placed because application start create process , cannot see logs in qt project. please me how can see logs in same time?

another way of doing instead of reading standard output qprocess mentioned in comments use qfilesystemwatcher , read file whenever qfilesystemwatcher::filechanged signal emitted. need either remember stopped reading or discard contents have read in if possible switch standard output more convenient.


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -