Unsolved How can I grep the word from QString?
-
Hi, I'm using qt5.5 on my computer.
For example I have a String like thisQString 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!
-
@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#readyReadStandardErrorBut 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.
-
@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?
-
@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? -
Rootpath method from QStorageInfo returns mount point of a device.