qDebug() << "Read requests:" << storage.readRequests(); qDebug() << "Write requests:" << storage.writeRequests(); qDebug() << "Read bytes:" << storage.bytesRead() / (1024 * 1024) << "MB"; qDebug() << "Write bytes:" << storage.bytesWritten() / (1024 * 1024) << "MB";这些代码会报错
时间: 2024-03-07 08:46:39 浏览: 55
Qt 5.13.2 qt.network.ssl: QSslSocket::connectToHostEncrypted: TLS initialization failed
如果你使用的是Qt 5.14.2或更高版本,那么可以使用下面的代码来获取磁盘读写请求的百分比:
```cpp
#include <QStorageInfo>
#include <QDebug>
int main()
{
QStorageInfo storage("/");
if (storage.isValid()) {
qDebug() << "Drive:" << storage.rootPath();
qDebug() << "Type:" << storage.fileSystemType();
qDebug() << "Total space:" << storage.bytesTotal() / (1024 * 1024) << "MB";
qDebug() << "Free space:" << storage.bytesFree() / (1024 * 1024) << "MB";
qDebug() << "Available space:" << storage.bytesAvailable() / (1024 * 1024) << "MB";
qDebug() << "Read requests:" << storage.readRequestsPerSecond();
qDebug() << "Write requests:" << storage.writeRequestsPerSecond();
qDebug() << "Read bytes:" << storage.bytesReadPerSecond() / (1024 * 1024) << "MB/s";
qDebug() << "Write bytes:" << storage.bytesWrittenPerSecond() / (1024 * 1024) << "MB/s";
}
}
```
在这个示例中,我们提供了一个路径来创建QStorageInfo对象。然后,我们使用isValid()方法来检查该设备是否有效。如果设备有效,我们使用其他方法来获取磁盘的信息,包括读写请求的速率和字节数。注意,这里使用了每秒读写请求数和每秒读写字节数。
阅读全文