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. Getting only the folder path to a line edit without selecting any file
QtWS25 Last Chance

Getting only the folder path to a line edit without selecting any file

Scheduled Pinned Locked Moved Solved General and Desktop
qtcreatorfolder pathbuttonclick
4 Posts 2 Posters 22.4k Views
  • 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.
  • L Offline
    L Offline
    Lasith
    wrote on last edited by
    #1

    In my Qt c++ application I want to get a folder path into a line edit without selecting anyfile!

    void MainWindow::on_button_clicked()
    {

    filePath=QFileDialog::getOpenFileName(this, "Get Any File");
    
    QDir d = QFileInfo(filePath).absoluteDir();
    QString absolute=d.absolutePath();
    ui->lineEdit->setText(absolute);
    

    }
    currently I use the above code to achieve it! Though the folder path only appears(without the file name) in the line edit a file in the relevant folder should be selected for it! I want to get folder path without selecting any file. (folder path should appear by opening the folder only)

    how can I get this done?

    1 Reply Last reply
    0
    • G Offline
      G Offline
      Gerd
      wrote on last edited by
      #2

      try
      filePath=QFileDialog::getExistingDirectory(this, "Get Any File");

      L 1 Reply Last reply
      3
      • G Gerd

        try
        filePath=QFileDialog::getExistingDirectory(this, "Get Any File");

        L Offline
        L Offline
        Lasith
        wrote on last edited by Lasith
        #3

        @Gerd Thanx bro it worked but I get folder path only upto the folder before the last folder!

        1 Reply Last reply
        1
        • G Offline
          G Offline
          Gerd
          wrote on last edited by
          #4

          just use the filePath without further modification, its already the complete path.
          This code

          QDir d = QFileInfo(filePath).absoluteDir();
          QString absolute=d.absolutePath();
          

          will lead you to the dir above the selected path...

          1 Reply Last reply
          1

          • Login

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