Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] How to get Total and Used Space of a SD Card in Qt Application?
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] How to get Total and Used Space of a SD Card in Qt Application?

Scheduled Pinned Locked Moved General and Desktop
16 Posts 4 Posters 7.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Stoned Jesus
    wrote on last edited by
    #1

    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 :)

    --
    Thanks & Regards,
    Stoned Jesus

    1 Reply Last reply
    0
    • L Offline
      L Offline
      leon.anavi
      wrote on last edited by
      #2

      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.

      http://anavi.org/

      1 Reply Last reply
      0
      • raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by
        #3

        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

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Stoned Jesus
          wrote on last edited by
          #4

          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]

          --
          Thanks & Regards,
          Stoned Jesus

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Stoned Jesus
            wrote on last edited by
            #5

            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]

            --
            Thanks & Regards,
            Stoned Jesus

            1 Reply Last reply
            0
            • L Offline
              L Offline
              leon.anavi
              wrote on last edited by
              #6

              [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?

              http://anavi.org/

              1 Reply Last reply
              0
              • S Offline
                S Offline
                Stoned Jesus
                wrote on last edited by
                #7

                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]

                --
                Thanks & Regards,
                Stoned Jesus

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  leon.anavi
                  wrote on last edited by
                  #8

                  [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.

                  http://anavi.org/

                  1 Reply Last reply
                  0
                  • raven-worxR Offline
                    raven-worxR Offline
                    raven-worx
                    Moderators
                    wrote on last edited by
                    #9

                    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

                    --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                    If you have a question please use the forum so others can benefit from the solution in the future

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      Stoned Jesus
                      wrote on last edited by
                      #10

                      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]

                      --
                      Thanks & Regards,
                      Stoned Jesus

                      1 Reply Last reply
                      0
                      • L Offline
                        L Offline
                        leon.anavi
                        wrote on last edited by
                        #11

                        [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.

                        http://anavi.org/

                        1 Reply Last reply
                        0
                        • S Offline
                          S Offline
                          Stoned Jesus
                          wrote on last edited by
                          #12

                          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]

                          --
                          Thanks & Regards,
                          Stoned Jesus

                          1 Reply Last reply
                          0
                          • L Offline
                            L Offline
                            leon.anavi
                            wrote on last edited by
                            #13

                            [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.

                            http://anavi.org/

                            1 Reply Last reply
                            0
                            • S Offline
                              S Offline
                              Stoned Jesus
                              wrote on last edited by
                              #14

                              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]

                              --
                              Thanks & Regards,
                              Stoned Jesus

                              1 Reply Last reply
                              0
                              • K Offline
                                K Offline
                                KA51O
                                wrote on last edited by
                                #15

                                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;
                                @

                                1 Reply Last reply
                                0
                                • S Offline
                                  S Offline
                                  Stoned Jesus
                                  wrote on last edited by
                                  #16

                                  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]

                                  --
                                  Thanks & Regards,
                                  Stoned Jesus

                                  1 Reply Last reply
                                  0

                                  • Login

                                  • Login or register to search.
                                  • First post
                                    Last post
                                  0
                                  • Categories
                                  • Recent
                                  • Tags
                                  • Popular
                                  • Users
                                  • Groups
                                  • Search
                                  • Get Qt Extensions
                                  • Unsolved