【问题标题】:How can I get required line?我怎样才能获得所需的线路?
【发布时间】:2021-08-23 09:05:57
【问题描述】:

我编写了代码,将 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)

如何做到这一点?

【问题讨论】:

  • 使用auto words = line.split("");auto number_str = words.at(words.length() - 2);

标签: qt qstring


【解决方案1】:
auto words = line.split(" "); auto number_str = words.at(words.length() - 2);

感谢 eyllanesc

【讨论】:

    猜你喜欢
    • 2011-06-04
    • 2017-05-25
    • 1970-01-01
    • 2013-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多