开发者

How to get user's download folder in Qt?

How do I ge开发者_如何转开发t the standard system / user paths in Qt?

What I really need is to get the location of the user's Downloads folder.


In Qt 4, there is QDesktopServices providing some user paths:

https://doc.qt.io/qt-4.8/qdesktopservices.html#StandardLocation-enum

It has e.g. Desktop and Documents but no specific Downloads folder.

In Qt 5, use QStandardPaths:

const QString downloadsFolder = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);


You can use QDir::homePath() to get a QString to the home directory of the current user's profile but I'm not sure that there is a "standard" download directory identified by the OS.


With Qt 5.15.0, on a fr-FR Linux (Manjaro) :

qDebug() << QStandardPaths::displayName(QStandardPaths::DownloadLocation);

returns :

"Téléchargement"

This is not the actual French "DownloadLocation" folder name, which is called "Téléchargements", with a plural s, because this folder usually contains more than one downloaded file. Btw, English localization seems to be "~/Downloads", according to Qt 5 online help, with the expected plural s.

Therefore, QStandardPaths::DownloadLocation is unreliable in French. If someone may file and follow the bug at Qt, this might help !

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜