Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    [Solved] ReadAll() (ls)

    General and Desktop
    3
    9
    1956
    Loading More Posts
    • 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
      jocala last edited by

      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 Reply Quote 0
      • dheerendra
        dheerendra Qt Champions 2022 last edited by

        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 Reply Quote 0
        • SGaist
          SGaist Lifetime Qt Champion last edited by

          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 Reply Quote 0
          • J
            jocala last edited by

            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 Reply Quote 0
            • SGaist
              SGaist Lifetime Qt Champion last edited by

              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 Reply Quote 0
              • J
                jocala last edited by

                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 Reply Quote 0
                • dheerendra
                  dheerendra Qt Champions 2022 last edited by

                  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 Reply Quote 0
                  • SGaist
                    SGaist Lifetime Qt Champion last edited by

                    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 Reply Quote 0
                    • J
                      jocala last edited by

                      Thanks for this. That tool is very handy.

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post