Getting only the folder path to a line edit without selecting any file
Solved
General and Desktop
-
wrote on 7 Oct 2017, 08:10 last edited by
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?
-
wrote on 7 Oct 2017, 09:55 last edited by
try
filePath=QFileDialog::getExistingDirectory(this, "Get Any File"); -
wrote on 9 Oct 2017, 14:23 last edited by
just use the filePath without further modification, its already the complete path.
This codeQDir d = QFileInfo(filePath).absoluteDir(); QString absolute=d.absolutePath();
will lead you to the dir above the selected path...
4/4