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. QStorageInfo not giving mount path

QStorageInfo not giving mount path

Scheduled Pinned Locked Moved Solved General and Desktop
14 Posts 4 Posters 2.9k 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
    saber
    wrote on last edited by
    #3

    and why i am not getting last 2 storage mount path ?

    mrjjM 1 Reply Last reply
    0
    • S saber

      and why i am not getting last 2 storage mount path ?

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #4

      @saber
      no idea. If you look in the linux - what are they ?
      maybe they dont have names at all and hence the empty strings.

      S 1 Reply Last reply
      0
      • mrjjM mrjj

        @saber
        no idea. If you look in the linux - what are they ?
        maybe they dont have names at all and hence the empty strings.

        S Offline
        S Offline
        saber
        wrote on last edited by
        #5

        @mrjj

        see the second debug output.

        last two is the name("Storage", "Fast"). but when i put them in here (QStorageInfo(l).rootPath() ) as "l" ,i am not getting the root path.

        mrjjM 1 Reply Last reply
        0
        • S saber

          @mrjj

          see the second debug output.

          last two is the name("Storage", "Fast"). but when i put them in here (QStorageInfo(l).rootPath() ) as "l" ,i am not getting the root path.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #6

          @saber
          Maybe they are not rootPaths ?

          S 1 Reply Last reply
          0
          • mrjjM mrjj

            @saber
            Maybe they are not rootPaths ?

            S Offline
            S Offline
            saber
            wrote on last edited by saber
            #7

            @mrjj i found the solution

            QStringList result;
                const auto allMounted = QStorageInfo::mountedVolumes();
                result.reserve(allMounted.size());
                for(auto& singleMounted : allMounted)
                result << singleMounted.rootPath();
            
                for(int i=0; i<result.count(); ++i ){
                    QString l = result.at(i);
                    if((l == "/run/user/1000" )| l == "/tmp" | l == "/run"){
                        result.removeAt(i);
                    }
                }
            

            output

            ("/", "/run/user/1000", "/run/media/shaber/Storage", "/run/media/shaber/Fast")
            

            but this ("/run/user/1000") is not removed automatically .
            why is it ? and how to do remove it?

            aha_1980A 1 Reply Last reply
            0
            • S saber

              @mrjj i found the solution

              QStringList result;
                  const auto allMounted = QStorageInfo::mountedVolumes();
                  result.reserve(allMounted.size());
                  for(auto& singleMounted : allMounted)
                  result << singleMounted.rootPath();
              
                  for(int i=0; i<result.count(); ++i ){
                      QString l = result.at(i);
                      if((l == "/run/user/1000" )| l == "/tmp" | l == "/run"){
                          result.removeAt(i);
                      }
                  }
              

              output

              ("/", "/run/user/1000", "/run/media/shaber/Storage", "/run/media/shaber/Fast")
              

              but this ("/run/user/1000") is not removed automatically .
              why is it ? and how to do remove it?

              aha_1980A Offline
              aha_1980A Offline
              aha_1980
              Lifetime Qt Champion
              wrote on last edited by
              #8

              @saber said in QStorageInfo not giving mount path:

              if((l == "/run/user/1000" )| l == "/tmp" | l == "/run"){
              result.removeAt(i);
              }

              What happens if you replace that with:

              if (l == "/run/user/1000" || l == "/tmp" || l == "/run") {
                result.removeAt(i);
              }
              

              Qt has to stay free or it will die.

              S 1 Reply Last reply
              0
              • aha_1980A aha_1980

                @saber said in QStorageInfo not giving mount path:

                if((l == "/run/user/1000" )| l == "/tmp" | l == "/run"){
                result.removeAt(i);
                }

                What happens if you replace that with:

                if (l == "/run/user/1000" || l == "/tmp" || l == "/run") {
                  result.removeAt(i);
                }
                
                S Offline
                S Offline
                saber
                wrote on last edited by
                #9

                @aha_1980
                nothing changed

                ("/", "/run/user/1000", "/run/media/shaber/Storage")
                

                same.

                is there any way to get just the mounted REAL partition .

                aha_1980A 1 Reply Last reply
                0
                • S saber

                  @aha_1980
                  nothing changed

                  ("/", "/run/user/1000", "/run/media/shaber/Storage")
                  

                  same.

                  is there any way to get just the mounted REAL partition .

                  aha_1980A Offline
                  aha_1980A Offline
                  aha_1980
                  Lifetime Qt Champion
                  wrote on last edited by aha_1980
                  #10

                  @saber: now I see it. if you use a debugger, you will notice the problem too.

                  you have a loop over x elements and compare element i against a pattern. if it matches, you remove the element.

                  But: therefore all following elements shift a position forward, which means you will miss the next element when the loop continues.

                  you can e.g. fix this by copying all wanted elements into a new list instead.

                  Regards

                  Qt has to stay free or it will die.

                  JonBJ 1 Reply Last reply
                  3
                  • aha_1980A aha_1980

                    @saber: now I see it. if you use a debugger, you will notice the problem too.

                    you have a loop over x elements and compare element i against a pattern. if it matches, you remove the element.

                    But: therefore all following elements shift a position forward, which means you will miss the next element when the loop continues.

                    you can e.g. fix this by copying all wanted elements into a new list instead.

                    Regards

                    JonBJ Online
                    JonBJ Online
                    JonB
                    wrote on last edited by JonB
                    #11

                    @aha_1980
                    Rather than copying to a new list, the simplest pattern to use when removing items from a list via a for () loop counter so as not to worry about shifting is always to count downward! :

                    for (int i = result.count() - 1; i >= 0; --i )
                        if (...)
                            result.removeAt(i);
                    

                    will work :)

                    aha_1980A 1 Reply Last reply
                    0
                    • JonBJ JonB

                      @aha_1980
                      Rather than copying to a new list, the simplest pattern to use when removing items from a list via a for () loop counter so as not to worry about shifting is always to count downward! :

                      for (int i = result.count() - 1; i >= 0; --i )
                          if (...)
                              result.removeAt(i);
                      

                      will work :)

                      aha_1980A Offline
                      aha_1980A Offline
                      aha_1980
                      Lifetime Qt Champion
                      wrote on last edited by
                      #12

                      @JonB

                      Rather then removing elements from a list he could just add the elements he really wants, by adding the check here

                      for(auto& singleMounted : allMounted)
                          result << singleMounted.rootPath();
                      

                      Sorry, could not resist ;)

                      Qt has to stay free or it will die.

                      JonBJ 1 Reply Last reply
                      0
                      • aha_1980A aha_1980

                        @JonB

                        Rather then removing elements from a list he could just add the elements he really wants, by adding the check here

                        for(auto& singleMounted : allMounted)
                            result << singleMounted.rootPath();
                        

                        Sorry, could not resist ;)

                        JonBJ Online
                        JonBJ Online
                        JonB
                        wrote on last edited by
                        #13

                        @aha_1980
                        Yes, but of course only works if you're copying/outputting the desired items somewhere. If you need to remove from a list, the downward pattern is worth knowing :)

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

                          my final solution

                           QStringList result;
                              const auto allMounted = QStorageInfo::mountedVolumes();
                              result.reserve(allMounted.size());
                              for(auto& singleMounted : allMounted)
                              result << singleMounted.rootPath();
                          
                          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