Unsolved remove string from a qstringlist
-
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.
last one is dvd drive.it also be removed from the qstringlist. -
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?
-
@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. -
@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}")));
-
-
-
@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.
-
@VRonin
can i get the mount path of mounted partition ?? -
@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.
-
@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??