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.

    0_1523617780665_Screenshot_2018-04-13_16-54-34.png
    last one is dvd drive.it also be removed from the qstringlist.

    0_1523617794670_r.png



  • 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}")));


  • Qt Champions 2017

    @VRonin

    +1 for the filter, even it may not be 100% stable.

    Unfortunately, mountedVolumes() also contains pseudo-fs:

    "/run"
    "/"
    "/run/lock"
    "/boot/efi"
    "/run/cgmanager/fs"
    "/run/user/1000"
    

    @saber: can you show your complete code? How is blockDevices() implemented?



  • @VRonin i need all the mounted and unmounted pertitions .
    and your code works but not quite well.it only removes sr0.sda ,sdb still there.

    @aha_1980 here is the code github

    please see the file named dashbord.cpp 29 line in dashbord folder.


  • Qt Champions 2017

    @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 ??


  • Moderators

    @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??


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.