Reputation: 2474
How to create cross platform QFileDialog
with default directory?
I have a code like
QFileDialog::getSaveFileName(this,"Save File","/home",tr("Any File (*.*);;Text file (*.txt);;Compressed file (*.zip *.tar *.rar);;Image (*.png *.xpm *.jpg *.tiff)"))
This works fine with Linux. But in windows the users directory will be "C:\Users"
. I don't know in Mac. I need this dialogue with default directory as user folder. How to do that?
I saw the toNativeSeparators()
but this need more line of codes. Is there any easiest way to do that?
Upvotes: 6
Views: 11054
Reputation: 877
this is my code
QString pathExport = dialog->getExistingDirectory(this, "Pilih Folder Export",QDir::homePath(),QFileDialog::ShowDirsOnly)+"/"+fileExport;
Upvotes: 4
Reputation: 1313
You can use also:
QDesktopServices::storageLocation(QDesktopServices::HomeLocation)
Which returns the user's home directory.
Upvotes: 4