Getting proper folder path
-
In my qt c++ application when the button is clicked the file dialog opens and when the select folder button in the file dialog is clicked the folder path is to be taken to the line edit in my application. But though the folder path appears the current folder does not appear at the end!
following is my code
void MainWindow::on_Button_clicked()
{
QString Filepath = QFileDialog::getExistingDirectory(this, "Get Any File");
QDir d = QFileInfo(Filepath).absoluteDir();
QString absolute=d.absolutePath();
ui->Path->setText(absolute);}
If the current folder is B and the parent folder is A(which is on the desktop) it should depict "Desktop/A/B" on the line edit but currently it shows only "Desktop/A"!
How can i correct this issue? -
@Lasith hi,
I don't quite understand why you go the detour over QFileInfo,
this, should do exactly what you want to happen
void MainWindow::on_Button_clicked() { QString Filepath = QFileDialog::getExistingDirectory(this, "Get Any File"); ui->Path->setText(Filepath); }
However if you insist on the useage QFileInfo, try it with
QString QFileInfo::absoluteFilePath()
void MainWindow::on_Button_clicked() { QString Filepath = QFileDialog::getExistingDirectory(this, "Get Any File"); QDir d = QFileInfo(Filepath).absoluteDir(); QString absolute=d.absoluteFilePath(); ui->Path->setText(absolute); }