[问题] qt 硬盘容量数据刷新

楼主: MOONY135 (谈无欲)   2017-06-16 13:35:09
开发平台(Platform): (Ex: Win10, Linux, ...)
win7
编译器(Ex: GCC, clang, VC++...)+目标环境(跟开发平台不同的话需列出)
vs 2015
额外使用到的函数库(Library Used): (Ex: OpenGL, ...)
qt5.7
问题(Question):
需要显示电脑所有储存设备的资讯
(可用的硬盘&剩余空间 需要用timer扫 可能是十秒扫
一次吧)
但考虑到软件开启时有随身碟的使用(ex开启时有插随身碟 然后有扫到资讯 但开启后拔
掉随身碟的用法)
可能就会造成软件崩溃
目前在侦测对于usb孔有操作是使用nativeEvent 加上 WM_DEVICECHANGE
不知道是否有推荐的做法呢?
QList<QStorageInfo> list = QStorageInfo::mountedVolumes();
qDebug() << "Volume Num: " << list.size();
for (QStorageInfo& si : list){
qDebug() << "rootPath: " << si.rootPath();
float free = si.bytesFree() / 1000 / 1000;
float toteal = si.bytesTotal() / 1000 / 1000;
float free_pre = free / toteal;
qDebug() << "Bytes Free: " << free;
qDebug() << "Bytes Total: " << toteal;
qDebug() << "Bytes Free(%): " << free_pre;
}
作者: uranusjr (←這人是超級笨蛋)   2017-06-16 13:37:00

Links booklink

Contact Us: admin [ a t ] ucptt.com