Qt World Summit: Submit your Presentation

Listing only the name of a folder in QDir

  • Hello and good morning, afternoon,

    i am trying to populate a listedit and have done so but what im trying to acomplish and cant seem to be able to do so is i got folders to load but i just want to show the folder name and that is it,

    and when folder is selected i want it to save the path to a string but cant seem to get this to work have tried elfen.DirName but this did not produce the desired affect here is what my code looks like currently.

        ELFENLIEDTOPFAN5RES::mGamePath = QString(getenv("TA_GAME_PATH")).replace('\\', '/');
        // cant use for dir derictly create wont let me try adding as dir path derictly.
        ELFENLIEDTOPFAN5RES::UserMapsFolder = QDir::cleanPath(QString("%1/usermaps/").arg(ELFENLIEDTOPFAN5RES::mGamePath));
        QDir elfen(QDir::cleanPath(QString("%1/usermaps/").arg(ELFENLIEDTOPFAN5RES::mGamePath)));
        foreach(QFileInfo var,elfen.entryInfoList())

    but this comes out with the full file path

    as shown below.
    alt text

    but trying to get zm_the map name but unable to find the way to do this in QT,
    Any Help is much appreciated thanks in advance

  • @elfenliedtopfan5

    First of all, do you know what these ". , ; " are?!
    So please use them :)
    You get headache from reading this.

    @elfenliedtopfan5 said in Listing only the name of a folder in QDir:


    If you write var.absoluteFilePath(), how should only the filename be there?
    Try var.fileName()

    To get a list of your selected items, use
    QList<QListWidgetItem *> QListWidget::selectedItems() const

    in combination with this signal (https://doc.qt.io/qt-5/qlistwidget.html#itemSelectionChanged)

  • To only get the name, a simpler way is use QDir::entryList instead of QDir::entryInfoList.

Log in to reply