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 13 Apr 2018, 11:10 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

    V 1 Reply Last reply 13 Apr 2018, 11:25
    0
    • S saber
      13 Apr 2018, 11:10

      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

      V Offline
      V Offline
      VRonin
      wrote on 13 Apr 2018, 11:25 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 13 Apr 2018, 11:30
      2
      • V VRonin
        13 Apr 2018, 11:25

        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 13 Apr 2018, 11:30 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.

        V 1 Reply Last reply 13 Apr 2018, 12:48
        0
        • S saber
          13 Apr 2018, 11:30

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

          V Offline
          V Offline
          VRonin
          wrote on 13 Apr 2018, 12:48 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

          A S 3 Replies Last reply 13 Apr 2018, 13:36
          2
          • V VRonin
            13 Apr 2018, 12:48

            @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}")));

            A Offline
            A Offline
            aha_1980
            Lifetime Qt Champion
            wrote on 13 Apr 2018, 13:36 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
            • V VRonin
              13 Apr 2018, 12:48

              @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 13 Apr 2018, 13:42 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.

              A 1 Reply Last reply 13 Apr 2018, 13:53
              0
              • S saber
                13 Apr 2018, 13:42

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

                A Offline
                A Offline
                aha_1980
                Lifetime Qt Champion
                wrote on 13 Apr 2018, 13:53 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
                • V VRonin
                  13 Apr 2018, 12:48

                  @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 16 Apr 2018, 12:42 last edited by
                  #8

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

                  jsulmJ 1 Reply Last reply 16 Apr 2018, 13:47
                  0
                  • S saber
                    16 Apr 2018, 12:42

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

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on 16 Apr 2018, 13:47 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 17 Apr 2018, 03:05
                    0
                    • jsulmJ jsulm
                      16 Apr 2018, 13:47

                      @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 17 Apr 2018, 03:05 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

                      1/10

                      13 Apr 2018, 11:10

                      • Login

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