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. How can I grep the word from QString?

How can I grep the word from QString?

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 2.2k 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.
  • V Offline
    V Offline
    victor wang
    wrote on last edited by A Former User
    #1

    Hi, I'm using qt5.5 on my computer.
    For example I have a String like this

    QString info;
    Process::executeProcessSync(QString("sh"),QStringList()<<"-c"<<"| grep \"/dev/sda1 on /run/media/\"",&info);
    

    And i just want to have "some words" inside the info in my other String.
    How can i do that?

    Please help!

    jsulmJ tomasz3dkT 2 Replies Last reply
    0
    • V victor wang

      Hi, I'm using qt5.5 on my computer.
      For example I have a String like this

      QString info;
      Process::executeProcessSync(QString("sh"),QStringList()<<"-c"<<"| grep \"/dev/sda1 on /run/media/\"",&info);
      

      And i just want to have "some words" inside the info in my other String.
      How can i do that?

      Please help!

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

      @victor-wang Do you mean you want to have what grep outputs?
      In this case you should first read http://doc.qt.io/qt-5/qprocess.html
      Especially http://doc.qt.io/qt-5/qprocess.html#readyReadStandardOutput and http://doc.qt.io/qt-5/qprocess.html#readyReadStandardError

      But why do you want to use grep to find something? Starting a new process is a very time consuming and resource intensive operation. It is much faster to do it directly in your app using http://doc.qt.io/qt-5/qstring.html#indexOf or regular expressions.

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

      1 Reply Last reply
      3
      • V victor wang

        Hi, I'm using qt5.5 on my computer.
        For example I have a String like this

        QString info;
        Process::executeProcessSync(QString("sh"),QStringList()<<"-c"<<"| grep \"/dev/sda1 on /run/media/\"",&info);
        

        And i just want to have "some words" inside the info in my other String.
        How can i do that?

        Please help!

        tomasz3dkT Offline
        tomasz3dkT Offline
        tomasz3dk
        wrote on last edited by
        #3

        @victor-wang I saw in command line arguments, that you probably want to find mounted volumes in your system, if i'm correct why not to use QStorageInfo, or read it directly form /proc/mounts file?

        V 1 Reply Last reply
        3
        • tomasz3dkT tomasz3dk

          @victor-wang I saw in command line arguments, that you probably want to find mounted volumes in your system, if i'm correct why not to use QStorageInfo, or read it directly form /proc/mounts file?

          V Offline
          V Offline
          victor wang
          wrote on last edited by
          #4

          @tomasz3dk
          Thank you! It is exactly what i want!
          Can i show the whole file path?
          I can only show the device path but not the file where i mounted at.
          Is there any way to show the directly path out?

          1 Reply Last reply
          0
          • tomasz3dkT Offline
            tomasz3dkT Offline
            tomasz3dk
            wrote on last edited by
            #5

            Rootpath method from QStorageInfo returns mount point of a device.

            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