[問題] qt 硬碟容量數據刷新

看板C_and_CPP作者 (談無慾)時間7年前 (2017/06/16 13:35), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串1/1
開發平台(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; } -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 210.242.6.98 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1497591312.A.001.html

文章代碼(AID): #1PGsuG01 (C_and_CPP)