0

我只需要解析vol命令的输出以获取 id 即仅abcd-1234用于QProcess. 这是我获取卷序列号的代码:

QProcess process;
process.start("cmd /c vol C:");
process.waitForFinished(-1);
QByteArray out = process.readAllStandardOutput();
qDebug() << out;

帮帮我,谢谢...

4

1 回答 1

1

您可以使用带有 QRegExp ( http://qt-project.org/doc/qt-4.8/qregexp.html )的正则表达式来查找 ID。vol 命令将始终返回相同的消息。因此,您可以逐行读取结果并搜索匹配的行:

QRegExp rx( "The Volume Serial Number is (.+)\\."); // Match the line with the ID and store it.
if ( rx.exactMatch( line ) {
    QString id = rx.capturedTexts(1); // The first elt is the entire matching text.
    qDebug() << id;
}
于 2013-05-29T12:34:56.423 回答