Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QFileDialog with default directory

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?

like image 386
Sanoob Avatar asked Apr 24 '13 07:04

Sanoob


2 Answers

Use QDir::home(), and then QDir::cdUp() to go up one.

like image 61
cmannett85 Avatar answered Oct 13 '22 18:10

cmannett85


You can use also:

QDesktopServices::storageLocation(QDesktopServices::HomeLocation)

Which returns the user's home directory.

like image 23
ariwez Avatar answered Oct 13 '22 20:10

ariwez