Reading file as written by external process
Solved
General and Desktop
-
What wrong with simply open the file and read it?
-
Hi and welcome to the forums
Yes it will work.
You have to use a timer or similar to read it from time to time
Disclaimer. fast code. needs more love to be solid.class Reader : QObject { QFile file; QTextStream in; QTimer timer; public: explicit Reader(QObject *parent) : QObject(parent) { connect(&timer, &QTimer::timeout, this, [this]() { while (!in.atEnd()) { QString line = in.readLine(); qDebug() << line; } }); } void Process(QString filename) { file.setFileName( filename); in.setDevice(&file); if ( ! file.open(QFile::ReadOnly)) { qDebug() << "open error" << file.errorString(); return; } timer.start(1000); qDebug() << "started"; } };
using
Reader *LogReader = new Reader(this); LogReader->Process("e:/test.txt");
Note file must exist when you try.