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] ReadAll() (ls)

[Solved] ReadAll() (ls)

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 Posters 2.6k 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.
  • J Offline
    J Offline
    jocala
    wrote on last edited by
    #1

    I need to offer a selection of mounted drives to the user for a procedure. The fragment below will show me the the contents of the directory where drive mounts live. How can I parse out the sd?? values (sda1,sdb1,etc) from the QString "command" and offer them to the user for choice?

    @ QProcess mount_dir;
    mount_dir.setProcessChannelMode(QProcess::MergedChannels);
    cstring = adb + " -s " + daddr+port + " shell su -c ls /storage/";
    mount_dir.start(cstring);
    mount_dir.waitForFinished(-1);
    command=mount_dir.readAll();@

    Thanks!

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      Did you get the output of the ls command from QProcess in your program ? If yes, it should be simple QString parsing. QString documentation should help you.

      If you have not got the output from QProcess do let me know. I can help with that.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        Please have a look at QProcess's "extended description":http://qt-project.org/doc/qt-5/qprocess.html#details you'll see how to properly build a parameter list and start a process with it

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • J Offline
          J Offline
          jocala
          wrote on last edited by
          #4

          Did you get the output of the ls command from QProcess in your program ? If >yes, it should be simple QString parsing.

          Actually, parsing is what I'd like a hand with. QProcess is working great.

          I have a qstring, "command" as shown in the code above. Among other things, it will contain strings of a pattern "sd??", *sda1,sdb1,sdc1, etc).

          Is there a way I can grab any substring matching the pattern "sd??" from the qstring returned by readAll()?

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            QRegularExpression comes to mind

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • J Offline
              J Offline
              jocala
              wrote on last edited by
              #6

              Yeah, I saw that and came across this fragment in my search:

              @
              QRegularExpression re("(\d+) (\w+)");
              QRegularExpressionMatch match = re.match("1234 word");
              if (match.hasMatch()) {
              QString digits = match.captured(1); // "1234"
              QString letters = match.captured(2); // "word
              }
              @

              Unfortunately, I'm not one of the 1 out of 10,000 coders who speak regex.

              So, what would a regex for "sd??" be?

              1 Reply Last reply
              0
              • dheerendraD Offline
                dheerendraD Offline
                dheerendra
                Qt Champions 2022
                wrote on last edited by
                #7

                This should help you.
                @
                QString str = "/dev/sda1";
                int index = str.indexOf("sd");
                QString newStr = str.mid(index,4);
                qDebug() << "Sub String ="<<newStr@

                Dheerendra
                @Community Service
                Certified Qt Specialist
                http://www.pthinks.com

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  There are several possibilities e.g.

                  "[a-z]{2}([a-z0-9]+)"

                  If you are looking for specifically sd plus something:

                  "sd([a-z0-9]+)"

                  From the top of my head.

                  You can build the "Regular Expressions Example" to help you build the regexp

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    jocala
                    wrote on last edited by
                    #9

                    Thanks for this. That tool is very handy.

                    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