Sanoob
Sanoob

Reputation: 2474

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?

Upvotes: 6

Views: 11054

Answers (3)

Sucipto
Sucipto

Reputation: 877

this is my code

QString pathExport = dialog->getExistingDirectory(this, "Pilih Folder Export",QDir::homePath(),QFileDialog::ShowDirsOnly)+"/"+fileExport;

Upvotes: 4

ariwez
ariwez

Reputation: 1313

You can use also:

QDesktopServices::storageLocation(QDesktopServices::HomeLocation)

Which returns the user's home directory.

Upvotes: 4

cmannett85
cmannett85

Reputation: 22366

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

Upvotes: 7

Related Questions