[SOLVED] How to get Total and Used Space of a SD Card in Qt Application?
-
Hi friends I am working on a Qt application where I need to display the total space and used space of a SD Card which is connected to my PC. I need to display them in the form of a string. E.g. 7.6 [GB] or 876 [MB]
Is their a Qt API that can help me achieve it? basically I am looking for an API to whom I can pass the path of the drive and it in-turn gives me the total and used space of the SD Card. I have tried QSystemStorageInfo and works well but I am looking for some other solution
Please help :)
-
Qt Mobility offers class "QSystemStorageInfo":http://doc.qt.digia.com/qtmobility/qsystemstorageinfo.html compatible with Qt 4.8. An "example usage is available here":http://www.developer.nokia.com/Community/Wiki/Working_with_QSystemStorageInfo_-_System_Information_API.
If you are using Qt 5 you should have a look at the "Qt 5 Add-on Modules":http://qt-project.org/wiki/Qt-Add-ons-Modules. The module Qt System Info is compatible with all platforms and provides class QStorageInfo.
-
the Qt module you are looking for is called "QtSystems":http://qt.gitorious.org/qt/qtsystems
Look at the class "QStorageInfo":http://qt.gitorious.org/qt/qtsystems/blobs/master/src/systeminfo/qstorageinfo.h. It provides you with the path, storage type, available disk space, etc.Only drawback is, that you will have to compile it yourself since it's not delivered with the official Qt module (I think it will be in the future sometime though)
Edit: too slow :P
-
Thanks for the reply. I have tried QSystemStorageInfo and works well but I am looking for some other solution :) I see a Windows API GetDiskFreeSpaceEx which gives Free Space. Is their similar API to get Used Space???
[quote author="leon.anavi" date="1367919181"]Qt Mobility offers class "QSystemStorageInfo":http://doc.qt.digia.com/qtmobility/qsystemstorageinfo.html compatible with Qt 4.8. An "example usage is available here":http://www.developer.nokia.com/Community/Wiki/Working_with_QSystemStorageInfo_-_System_Information_API.
If you are using Qt 5 you should have a look at the "Qt 5 Add-on Modules":http://qt-project.org/wiki/Qt-Add-ons-Modules. The module Qt System Info is compatible with all platforms and provides class QStorageInfo.[/quote]
-
My project doesnt allows me to use QStorageInfo. That's why I am looking for alternative solution :) I see a Windows API GetDiskFreeSpaceEx which gives Free Space. Is their similar API to get Used Space???
[quote author="raven-worx" date="1367919355"]the Qt module you are looking for is called "QtSystems":http://qt.gitorious.org/qt/qtsystems
Look at the class "QStorageInfo":http://qt.gitorious.org/qt/qtsystems/blobs/master/src/systeminfo/qstorageinfo.h. It provides you with the path, storage type, available disk space, etc.Only drawback is, that you will have to compile it yourself since it's not delivered with the official Qt module (I think it will be in the future sometime though)[/quote]
-
[quote author="Stoned Jesus" date="1367919469"]My project doesnt allows me to use QStorageInfo. That's why I am looking for alternative solution :)
[/quote]Please excuse my curiosity but why are you searching for another API if QSystemStorageInfo is working fine and why you cannot use it in your project?
-
QtMobility is not delivered with Qt's official module thats why we have been told to avoid it :(
[quote author="leon.anavi" date="1367919568"]
[quote author="Stoned Jesus" date="1367919469"]My project doesnt allows me to use QStorageInfo. That's why I am looking for alternative solution :)
[/quote]Please excuse my curiosity but why are you searching for another API if QSystemStorageInfo is working fine and why you cannot use it in your project?[/quote]
-
[quote author="Stoned Jesus" date="1367919731"]QtMobility is not delivered with Qt's official module thats why we have been told to avoid it :(
[/quote]
Yes, you should use Qt System Info module if you are using Qt 5. But if you are using 4.8 it is OK to include Qt Mobility.
-
QStrorageInfo uses GetDiskFreeSpaceEx internally btw.
if you are only allowed to use "standard" Qt libraries you won't be able to implement what you want
-
I am using Qt 4.8. Unfortunately I cant use Qtmobility.... Oh!! I hate these restrictions :(
[quote author="leon.anavi" date="1367919874"]
[quote author="Stoned Jesus" date="1367919731"]QtMobility is not delivered with Qt's official module thats why we have been told to avoid it :([/quote]
Yes, you should use Qt System Info module if you are using Qt 5. But if you are using 4.8 it is OK to include Qt Mobility.[/quote]
-
[quote author="raven-worx" date="1367919914"]# QStrorageInfo uses GetDiskFreeSpaceEx internally btw.[/quote]
Methods availableDiskSpace and totalDiskSpace are public so the total free space can be calculated very easily.
-
Thanks Raven.
[quote author="leon.anavi" date="1367920058"]
[quote author="raven-worx" date="1367919914"]# QStrorageInfo uses GetDiskFreeSpaceEx internally btw.[/quote]Methods availableDiskSpace and totalDiskSpace are public so the total free space can be calculated very easily.[/quote]
-
[quote author="Stoned Jesus" date="1367919731"]QtMobility is not delivered with Qt's official module thats why we have been told to avoid it :(
[/quote]OK, if you want to use Qt 4.8 and you don't want to use Qt Mobility then you have to implement your own solution using the specific API of the platform that you are targeting. Qt does not provide other APIs for this task.
-
Yes I will get into that and post the answer here :)
[quote author="leon.anavi" date="1367920547"]
[quote author="Stoned Jesus" date="1367919731"]QtMobility is not delivered with Qt's official module thats why we have been told to avoid it :(
[/quote]OK, if you want to use Qt 4.8 and you don't want to use Qt Mobility then you have to implement your own solution using the specific API of the platform that you are targeting. Qt does not provide other APIs for this task.[/quote]
-
In case you're allowed to use boost, there's "boost::filesystem":http://www.boost.org/doc/libs/1_53_0/libs/filesystem/doc/index.htm .
@
boost::filesystem::path p (filepath);
boost::filesystem::space_info s = boost::filesystem::space(p);
quint64 uFreeStorage = s.available;
quint64 uTotalStorage = s.capacity;
@ -
Wow this worked :) thanks
[quote author="KA51O" date="1367922920"]In case you're allowed to use boost, there's "boost::filesystem":http://www.boost.org/doc/libs/1_53_0/libs/filesystem/doc/index.htm .
@
boost::filesystem::path p (filepath);
boost::filesystem::space_info s = boost::filesystem::space(p);
quint64 uFreeStorage = s.available;
quint64 uTotalStorage = s.capacity;
@[/quote]