[問題] 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