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?
Use QDir::home()
, and then QDir::cdUp()
to go up one.
You can use also:
QDesktopServices::storageLocation(QDesktopServices::HomeLocation)
Which returns the user's home directory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With