I'm having a problem parsing /proc/stat
with Qt.
The problem I'm having is QFile
states /proc/stat
is both open and readable.
When attempting to read the lines individually, QTextStream
apparently dictates the stream has completed, but I know this isn't the case by running a cat /proc/stat
.
None of the code in the while
loop is executed. Any advice or suggestions?
int UsageStatistics::handle_timeout(const ACE_Time_Value& currentTime, const void* param) {
INFO("Handling timeout\n");
QFile file(QString("/proc/stat"));
if (!file.open(QIODevice::ReadOnly)) {
ERROR("Unable to open file %s, aborting\n", file.fileName().toStdString().c_str());
return false;
}
if (!file.isReadable()) {
ERROR("Unable to read file %s, aborting\n", file.fileName().toStdString().c_str());
return false;
}
QTextStream in(&file);
while (!in.atEnd()) {
QString line = in.readLine();
INFO("%s\n", line.toStdString().c_str());
/// processing
}
file.close();
return true;
}