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



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



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



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



  • 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...



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