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. Listing only the name of a folder in QDir
Forum Updated to NodeBB v4.3 + New Features

Listing only the name of a folder in QDir

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 717 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.
  • E Offline
    E Offline
    elfenliedtopfan5
    wrote on last edited by
    #1

    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())
        {
    
            ui->listWidget->addItem(var.absoluteFilePath());
        }
    

    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

    Pl45m4P 1 Reply Last reply
    0
    • E elfenliedtopfan5

      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())
          {
      
              ui->listWidget->addItem(var.absoluteFilePath());
          }
      

      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

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by Pl45m4
      #2

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

      ui->listWidget->addItem(var.absoluteFilePath());

      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
      https://doc.qt.io/qt-5/qlistwidget.html#selectedItems

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


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      1 Reply Last reply
      4
      • B Offline
        B Offline
        Bonnie
        wrote on last edited by
        #3

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

        1 Reply Last reply
        3

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved