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. remove string from a qstringlist
Forum Updated to NodeBB v4.3 + New Features

remove string from a qstringlist

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 4 Posters 3.1k Views
  • 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 saber
    #1

    i put my linux partition in a qstringlist and add this qstringkist in a listview.but the list also have some items that are not partition .so how can i remove them from qstringlist.
    this non-partition usually has only 3 letter in name.

    0_1523617780665_Screenshot_2018-04-13_16-54-34.png
    last one is dvd drive.it also be removed from the qstringlist.

    0_1523617794670_r.png

    VRoninV 1 Reply Last reply
    0
    • S saber

      i put my linux partition in a qstringlist and add this qstringkist in a listview.but the list also have some items that are not partition .so how can i remove them from qstringlist.
      this non-partition usually has only 3 letter in name.

      0_1523617780665_Screenshot_2018-04-13_16-54-34.png
      last one is dvd drive.it also be removed from the qstringlist.

      0_1523617794670_r.png

      VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      I think you should focus on not adding them in the first place

      @saber said in remove string from a qstringlist:

      i put my linux partition in a qstringlist

      How?

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      S 1 Reply Last reply
      2
      • VRoninV VRonin

        I think you should focus on not adding them in the first place

        @saber said in remove string from a qstringlist:

        i put my linux partition in a qstringlist

        How?

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

        @VRonin i can't do that.
        because the cpp file that i use to collect partition is not licensed gpl.
        so i need to do that steps above.

        VRoninV 1 Reply Last reply
        0
        • S saber

          @VRonin i can't do that.
          because the cpp file that i use to collect partition is not licensed gpl.
          so i need to do that steps above.

          VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by VRonin
          #4

          @saber said in remove string from a qstringlist:

          is not licensed gpl.

          I thought Qt was already capable of doing that. I don't have a unix system available at the moment but this should work:

          QStringList result;
          const auto allMounted = QStorageInfo::mountedVolumes();
          result.reserve(allMounted.size());
          for(auto& singleMounted : allMounted)
          result << singleMounted.displayName();
          

          If you really want to go the remove way, however, you just need to use stringList = stringList.filter(QRegularExpression(QStringLiteral("[a-z]{3}")));

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          aha_1980A S 3 Replies Last reply
          2
          • VRoninV VRonin

            @saber said in remove string from a qstringlist:

            is not licensed gpl.

            I thought Qt was already capable of doing that. I don't have a unix system available at the moment but this should work:

            QStringList result;
            const auto allMounted = QStorageInfo::mountedVolumes();
            result.reserve(allMounted.size());
            for(auto& singleMounted : allMounted)
            result << singleMounted.displayName();
            

            If you really want to go the remove way, however, you just need to use stringList = stringList.filter(QRegularExpression(QStringLiteral("[a-z]{3}")));

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

            @VRonin

            +1 for the filter, even it may not be 100% stable.

            Unfortunately, mountedVolumes() also contains pseudo-fs:

            "/run"
            "/"
            "/run/lock"
            "/boot/efi"
            "/run/cgmanager/fs"
            "/run/user/1000"
            

            @saber: can you show your complete code? How is blockDevices() implemented?

            Qt has to stay free or it will die.

            1 Reply Last reply
            2
            • VRoninV VRonin

              @saber said in remove string from a qstringlist:

              is not licensed gpl.

              I thought Qt was already capable of doing that. I don't have a unix system available at the moment but this should work:

              QStringList result;
              const auto allMounted = QStorageInfo::mountedVolumes();
              result.reserve(allMounted.size());
              for(auto& singleMounted : allMounted)
              result << singleMounted.displayName();
              

              If you really want to go the remove way, however, you just need to use stringList = stringList.filter(QRegularExpression(QStringLiteral("[a-z]{3}")));

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

              @VRonin i need all the mounted and unmounted pertitions .
              and your code works but not quite well.it only removes sr0.sda ,sdb still there.

              @aha_1980 here is the code github

              please see the file named dashbord.cpp 29 line in dashbord folder.

              aha_1980A 1 Reply Last reply
              0
              • S saber

                @VRonin i need all the mounted and unmounted pertitions .
                and your code works but not quite well.it only removes sr0.sda ,sdb still there.

                @aha_1980 here is the code github

                please see the file named dashbord.cpp 29 line in dashbord folder.

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

                @saber Ok, so blockDevices() is your own function which queries the drives via DBus.

                So while you could filter them out later, better would be to query actual partitions via DBus. Maybe someone with more DBus knowledge can tell if that is possible, and how.

                Qt has to stay free or it will die.

                1 Reply Last reply
                2
                • VRoninV VRonin

                  @saber said in remove string from a qstringlist:

                  is not licensed gpl.

                  I thought Qt was already capable of doing that. I don't have a unix system available at the moment but this should work:

                  QStringList result;
                  const auto allMounted = QStorageInfo::mountedVolumes();
                  result.reserve(allMounted.size());
                  for(auto& singleMounted : allMounted)
                  result << singleMounted.displayName();
                  

                  If you really want to go the remove way, however, you just need to use stringList = stringList.filter(QRegularExpression(QStringLiteral("[a-z]{3}")));

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

                  @VRonin
                  can i get the mount path of mounted partition ??

                  jsulmJ 1 Reply Last reply
                  0
                  • S saber

                    @VRonin
                    can i get the mount path of mounted partition ??

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @saber said in remove string from a qstringlist:

                    can i get the mount path of mounted partition ??

                    One possibility would be to execute "mount" command using QProcess and parse its output.

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    S 1 Reply Last reply
                    0
                    • jsulmJ jsulm

                      @saber said in remove string from a qstringlist:

                      can i get the mount path of mounted partition ??

                      One possibility would be to execute "mount" command using QProcess and parse its output.

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

                      @jsulm i did this

                      QStringList result;
                          const auto allMounted = QStorageInfo::mountedVolumes();
                          result.reserve(allMounted.size());
                          for(auto& singleMounted : allMounted)
                          result << singleMounted.displayName();
                      
                      //    const auto allMounted = QStorageInfo::mountedVolumes();
                          for(int i=0; i<result.count(); ++i ){
                              QString l;
                              l = result.at(i);
                              QStorageInfo(l).rootPath();
                              qDebug()<<QStorageInfo(l).rootPath();
                          }
                      

                      output

                      "/run"
                      "/"
                      "/tmp"
                      "/run/user/1000"
                      ""
                      ""
                      ("/run", "/", "/tmp", "/run/user/1000", "Storage", "Fast")
                      

                      @aha_1980 @VRonin guys , i want also last two storage mounted path and remove "/run" "/tmp" , "/run/user/1000" .but how??

                      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