문제

In my program, I have a button that opens a getOpenFileName dialog like this:

path = QFileDialog::getOpenFileName(this, tr("Select region"), "%APPDATA%", tr("region file"));

I want the dialog to default to the users AppData folder. All users are running Windows (XP or higher). How could I ensure it defaults to AppData?

도움이 되었습니까?

해결책

You can use QDesktopServices static method (Qt4):

QString path = QDesktopServices::storageLocation(QDesktopServices::DataLocation);

In Qt5:

QString path = QStandardPaths::standardLocations(QStandardPaths::DataLocation).at(0);

To get Roaming folder:

QSettings settings(QSettings::IniFormat, QSettings::UserScope, "AppName", "application");
QString location = QFileInfo(settings.fileName()).absolutePath() + "/";

In my case path was:

C:/Users/maxim.makhun/AppData/Roaming/AppName/

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top