我编写了代码,将 QProcess 的输出转换为 QTextStream,而不是显示我需要的行:
QProcess p;
p.start("fdisk",QStringList() << "/dev/sdb" << "-l");
p.waitForFinished();
QString processOutput = p.readAll();
QTextStream processOutputTextStream(&processOutput);
QString line;
while(!processOutputTextStream.atEnd()){
line = processOutputTextStream.readLine();
if(line.contains("Disk /dev/sdb:")){
qDebug() << line;
}
}
输出:
"Disk /dev/sdb: 28.67 GiB, 30765219840 bytes, 60088320 sectors"
我只需要最后一个数字 (60088320)
如何做到这一点?
答案 0 :(得分:0)
auto words = line.split(" "); auto number_str = words.at(words.length() - 2);
感谢 eyllanesc