Qt remembers the last opened folder

I am using QFileDialog :: openfilename to input a file from the user as input and I have specified a default folder that should be displayed when the user dialog is opened. But qt somehow remembers the last opened folder when filedialog is opened multiple times. But I want this default folder to be the original folder shown to the user, not the last folder open. In this I am not doing anything to keep the latest public information anywhere. Please tell me what the problem is and how to fix it.


source to share

2 answers

It is clearly stated here . The third parameter to getOpenFileName is dir.

The working directory of the files dialog will be set to directory. If dir contains a filename, the file will be selected.



Use this. setDirectory(str);

set the default path and you never get the last open directory.

void MainWindow::on_pushButton_clicked()
    QFileDialog dia;
    dia.setDirectory("D:/");//or another default folder

    QString path1 = dia.getOpenFileName(this,"Choose file");




All Articles