我想在linux机器上读取和解析/ proc / PID / status文件的内容,但是QTextStream.atEnd在开始读取时总是返回true。 代码:
QString procDirectory = "/proc/"; procDirectory.append(QString::number(PID)); procDirectory.append("/status"); QFile inputFile(procDirectory); if (inputFile.open(QIODevice::ReadOnly)) { QTextStream in(&inputFile); QString line; while (!in.atEnd()) { line = in.readLine();文件存在,如果我在没有while表达式的情况下手动读取行,则会正常读取文件。
我错过了一些明显的东西吗
(Debian 8 x64,QT 5.4.1 x64,gcc 4.9.2)
I want to read and parse contents of the /proc/PID/status file on a linux machine, but the QTextStream.atEnd is always returning true when starting to read. The code:
QString procDirectory = "/proc/"; procDirectory.append(QString::number(PID)); procDirectory.append("/status"); QFile inputFile(procDirectory); if (inputFile.open(QIODevice::ReadOnly)) { QTextStream in(&inputFile); QString line; while (!in.atEnd()) { line = in.readLine();File exists and if I read lines manually without the while expression, the files are read normally.
Did I miss something obvious?
(Debian 8 x64, QT 5.4.1 x64, gcc 4.9.2)
最满意答案
循环遍历这些流的首选方法是使用do / while循环。 这是为了允许流在进行任何查询(如atEnd)之前正确检测Unicode。
QTextStream stream(stdin); QString line; do { line = stream.readLine(); } while (!line.isNull());The preferred way oft looping over these streams is with a do/while loop. This is for allowing the stream to detect Unicode correctly before any queries (like atEnd) are made.
QTextStream stream(stdin); QString line; do { line = stream.readLine(); } while (!line.isNull());更多推荐
发布评论