Qt5.1.0怎么获取桌面路径

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Qt5.1.0怎么获取桌面路径相关的知识,希望对你有一定的参考价值。

参考技术A 对于经常喜欢将文件放置在电脑桌面的朋友来说,最佳的优化方案是将桌面路径更改为非系统盘,因为桌面文件默认是存放在系统盘,电脑开关机都会扫描到,文件过多会影响速度,而我们通过修改Win10桌面文件路径,就可以很好的解决这一问题。那么Win10桌面路径怎么改?接下来小编为您带来Win10深度优化之桌面文件路径更改教程。 Win10桌面文件路径更改教程方法步骤如下: 一、首先进入Win10这台电脑,然后进入系统盘,然后依次进入【用户】--【系统账号文件夹】--然后找到【桌面】文件夹,然后在【桌面】文件夹上鼠标右键,在弹出的菜单中选择打开【属性】,如下图所示。 【注】 由于笔者电脑安装了Win8.1/Win10双系统,Win10是安装在H盘,因此以上系统盘进入的是H盘,一般来说,如果大家只安装了一个系统,那么系统盘默认是C盘。 二、在打开的桌面属性对话框中,先切换到选项卡中的【位置】,然后点击底部的【移动】,如下图所示: 三、在弹出的“选择一个目标”对话框中,我们点击左侧的这台电脑,然后选择一个非系统盘中的“桌面”文件夹,如下图所示。 注:笔者将Win10桌面路径更改为了非系统的E盘下,大家可以事先在E盘建立一个“桌面”文件夹,然后在第三步这里,直接选择即可,也可以在选择的时候,临时创建一个。 四、完成目标文件夹选择后,点击底部的【确定】就可以完成Win10桌面路径的更改了,如下图所示。 通过以上大致四个步骤,我们就成功的将Win10桌面路径由系统盘转移到了其他非系统盘,以后在桌面存放的文件,都不是在系统盘,这样可以有利于的减少系统盘压力,提升电脑开关机速度,属于深度电脑优化小技巧。

QT软件开发: 获取下载桌面临时文件....等系统默认目录

QT版本: 5.12.6

头文件:

#include <QStandardPaths>

示例代码:

    qDebug()<<"系统字体目录路径:"<<QStandardPaths::standardLocations(QStandardPaths::FontsLocation);
    qDebug()<<"系统桌面目录路径:"<<QStandardPaths::standardLocations(QStandardPaths::DesktopLocation);
    qDebug()<<"用户文档目录路径:"<<QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation);
    qDebug()<<"用户音乐目录路径:"<<QStandardPaths::standardLocations(QStandardPaths::MusicLocation);
    qDebug()<<"用户图片目录路径:"<<QStandardPaths::standardLocations(QStandardPaths::PicturesLocation);
    qDebug()<<"系统临时文件目录路径:"<<QStandardPaths::standardLocations(QStandardPaths::TempLocation);
    qDebug()<<"系统缓存目录路径:"<<QStandardPaths::standardLocations(QStandardPaths::CacheLocation);
    qDebug()<<"系统下载目录路径:"<<QStandardPaths::standardLocations(QStandardPaths::DownloadLocation);
    qDebug()<<"系统缓存目录路径:"<<QStandardPaths::standardLocations(QStandardPaths::CacheLocation);

MacOS与Windows系统的目录路径说明:

Path type

macOS

Windows

DesktopLocation

"~/Desktop"

"C:/Users/<USER>/Desktop"

DocumentsLocation

"~/Documents"

"C:/Users/<USER>/Documents"

FontsLocation

"/System/Library/Fonts" (not writable)

"C:/Windows/Fonts" (not writable)

ApplicationsLocation

"/Applications" (not writable)

"C:/Users/<USER>/AppData/Roaming/Microsoft/Windows/Start Menu/Programs"

MusicLocation

"~/Music"

"C:/Users/<USER>/Music"

MoviesLocation

"~/Movies"

"C:/Users/<USER>/Videos"

PicturesLocation

"~/Pictures"

"C:/Users/<USER>/Pictures"

TempLocation

randomly generated by the OS

"C:/Users/<USER>/AppData/Local/Temp"

HomeLocation

"~"

"C:/Users/<USER>"

DataLocation

"~/Library/Application Support/<APPNAME>", "/Library/Application Support/<APPNAME>". "<APPDIR>/../Resources"

"C:/Users/<USER>/AppData/Local/<APPNAME>", "C:/ProgramData/<APPNAME>", "<APPDIR>", "<APPDIR>/data", "<APPDIR>/data/<APPNAME>"

CacheLocation

"~/Library/Caches/<APPNAME>", "/Library/Caches/<APPNAME>"

"C:/Users/<USER>/AppData/Local/<APPNAME>/cache"

GenericDataLocation

"~/Library/Application Support", "/Library/Application Support"

"C:/Users/<USER>/AppData/Local", "C:/ProgramData", "<APPDIR>", "<APPDIR>/data"

RuntimeLocation

"~/Library/Application Support"

"C:/Users/<USER>"

ConfigLocation

"~/Library/Preferences"

"C:/Users/<USER>/AppData/Local/<APPNAME>", "C:/ProgramData/<APPNAME>"

GenericConfigLocation

"~/Library/Preferences"

"C:/Users/<USER>/AppData/Local", "C:/ProgramData"

DownloadLocation

"~/Downloads"

"C:/Users/<USER>/Documents"

GenericCacheLocation

"~/Library/Caches", "/Library/Caches"

"C:/Users/<USER>/AppData/Local/cache"

AppDataLocation

"~/Library/Application Support/<APPNAME>", "/Library/Application Support/<APPNAME>". "<APPDIR>/../Resources"

"C:/Users/<USER>/AppData/Roaming/<APPNAME>", "C:/ProgramData/<APPNAME>", "<APPDIR>", "<APPDIR>/data", "<APPDIR>/data/<APPNAME>"

AppLocalDataLocation

"~/Library/Application Support/<APPNAME>", "/Library/Application Support/<APPNAME>". "<APPDIR>/../Resources"

"C:/Users/<USER>/AppData/Local/<APPNAME>", "C:/ProgramData/<APPNAME>", "<APPDIR>", "<APPDIR>/data", "<APPDIR>/data/<APPNAME>"

AppConfigLocation

"~/Library/Preferences/<APPNAME>"

"C:/Users/<USER>/AppData/Local/<APPNAME>", "C:/ProgramData/<APPNAME>"

Linux系统的目录路径说明:

Path type

Linux

DesktopLocation

"~/Desktop"

DocumentsLocation

"~/Documents"

FontsLocation

"~/.fonts"

ApplicationsLocation

"~/.local/share/applications", "/usr/local/share/applications", "/usr/share/applications"

MusicLocation

"~/Music"

MoviesLocation

"~/Videos"

PicturesLocation

"~/Pictures"

TempLocation

"/tmp"

HomeLocation

"~"

DataLocation

"~/.local/share/<APPNAME>", "/usr/local/share/<APPNAME>", "/usr/share/<APPNAME>"

CacheLocation

"~/.cache/<APPNAME>"

GenericDataLocation

"~/.local/share", "/usr/local/share", "/usr/share"

RuntimeLocation

"/run/user/<USER>"

ConfigLocation

"~/.config", "/etc/xdg"

GenericConfigLocation

"~/.config", "/etc/xdg"

DownloadLocation

"~/Downloads"

GenericCacheLocation

"~/.cache"

AppDataLocation

"~/.local/share/<APPNAME>", "/usr/local/share/<APPNAME>", "/usr/share/<APPNAME>"

AppLocalDataLocation

"~/.local/share/<APPNAME>", "/usr/local/share/<APPNAME>", "/usr/share/<APPNAME>"

AppConfigLocation

"~/.config/<APPNAME>", "/etc/xdg/<APPNAME>"

Android、IOS系统的目录路径说明:

Path type

Android

iOS

DesktopLocation

"<APPROOT>/files"

"<APPROOT>/Documents/Desktop"

DocumentsLocation

"<USER>/Documents", "<USER>/<APPNAME>/Documents"

"<APPROOT>/Documents"

FontsLocation

"/system/fonts" (not writable)

"<APPROOT>/Library/Fonts"

ApplicationsLocation

not supported (directory not readable)

not supported

MusicLocation

"<USER>/Music", "<USER>/<APPNAME>/Music"

"<APPROOT>/Documents/Music"

MoviesLocation

"<USER>/Movies", "<USER>/<APPNAME>/Movies"

"<APPROOT>/Documents/Movies"

PicturesLocation

"<USER>/Pictures", "<USER>/<APPNAME>/Pictures"

"<APPROOT>/Documents/Pictures", "assets-library://"

TempLocation

"<APPROOT>/cache"

"<APPROOT>/tmp"

HomeLocation

"<APPROOT>/files"

"<APPROOT>" (not writable)

DataLocation

"<APPROOT>/files", "<USER>/<APPNAME>/files"

"<APPROOT>/Library/Application Support"

CacheLocation

"<APPROOT>/cache", "<USER>/<APPNAME>/cache"

"<APPROOT>/Library/Caches"

GenericDataLocation

"<USER>"

"<APPROOT>/Documents"

RuntimeLocation

"<APPROOT>/cache"

not supported

ConfigLocation

"<APPROOT>/files/settings"

"<APPROOT>/Library/Preferences"

GenericConfigLocation

"<APPROOT>/files/settings" (there is no shared settings)

"<APPROOT>/Library/Preferences"

DownloadLocation

"<USER>/Downloads", "<USER>/<APPNAME>/Downloads"

"<APPROOT>/Documents/Downloads"

GenericCacheLocation

"<APPROOT>/cache" (there is no shared cache)

"<APPROOT>/Library/Caches"

AppDataLocation

"<APPROOT>/files", "<USER>/<APPNAME>/files"

"<APPROOT>/Library/Application Support"

AppConfigLocation

"<APPROOT>/files/settings"

"<APPROOT>/Library/Preferences/<APPNAME>"

AppLocalDataLocation

"<APPROOT>/files", "<USER>/<APPNAME>/files"

"<APPROOT>/Library/Application Support"

 

每个枚举的功能介绍:

Constant

Value

Description

QStandardPaths::DesktopLocation

0

Returns the user's desktop directory. This is a generic value. On systems with no concept of a desktop, this is the same as QStandardPaths::HomeLocation.

QStandardPaths::DocumentsLocation

1

Returns the directory containing user document files. This is a generic value. The returned path is never empty.

QStandardPaths::FontsLocation

2

Returns the directory containing user's fonts. This is a generic value. Note that installing fonts may require additional, platform-specific operations.

QStandardPaths::ApplicationsLocation

3

Returns the directory containing the user applications (either executables, application bundles, or shortcuts to them). This is a generic value. Note that installing applications may require additional, platform-specific operations. Files, folders or shortcuts in this directory are platform-specific.

QStandardPaths::MusicLocation

4

Returns the directory containing the user's music or other audio files. This is a generic value. If no directory specific for music files exists, a sensible fallback for storing user documents is returned.

QStandardPaths::MoviesLocation

5

Returns the directory containing the user's movies and videos. This is a generic value. If no directory specific for movie files exists, a sensible fallback for storing user documents is returned.

QStandardPaths::PicturesLocation

6

Returns the directory containing the user's pictures or photos. This is a generic value. If no directory specific for picture files exists, a sensible fallback for storing user documents is returned.

QStandardPaths::TempLocation

7

Returns a directory where temporary files can be stored. The returned value might be application-specific, shared among other applications for this user, or even system-wide. The returned path is never empty.

QStandardPaths::HomeLocation

8

Returns the user's home directory (the same as QDir::homePath()). On Unix systems, this is equal to the HOME environment variable. This value might be generic or application-specific, but the returned path is never empty.

QStandardPaths::DataLocation

9

Returns the same value as AppLocalDataLocation. This enumeration value is deprecated. Using AppDataLocation is preferable since on Windows, the roaming path is recommended.

QStandardPaths::CacheLocation

10

Returns a directory location where user-specific non-essential (cached) data should be written. This is an application-specific directory. The returned path is never empty.

QStandardPaths::GenericCacheLocation

15

Returns a directory location where user-specific non-essential (cached) data, shared across applications, should be written. This is a generic value. Note that the returned path may be empty if the system has no concept of shared cache.

QStandardPaths::GenericDataLocation

11

Returns a directory location where persistent data shared across applications can be stored. This is a generic value. The returned path is never empty.

QStandardPaths::RuntimeLocation

12

Returns a directory location where runtime communication files should be written, like Unix local sockets. This is a generic value. The returned path may be empty on some systems.

QStandardPaths::ConfigLocation

13

Returns a directory location where user-specific configuration files should be written. This may be either a generic value or application-specific, and the returned path is never empty.

QStandardPaths::DownloadLocation

14

Returns a directory for user's downloaded files. This is a generic value. If no directory specific for downloads exists, a sensible fallback for storing user documents is returned.

QStandardPaths::GenericConfigLocation

16

Returns a directory location where user-specific configuration files shared between multiple applications should be written. This is a generic value and the returned path is never empty.

QStandardPaths::AppDataLocation

17

Returns a directory location where persistent application data can be stored. This is an application-specific directory. To obtain a path to store data to be shared with other applications, use QStandardPaths::GenericDataLocation. The returned path is never empty. On the Windows operating system, this returns the roaming path. This enum value was added in Qt 5.4.

QStandardPaths::AppLocalDataLocation

DataLocation

Returns the local settings path on the Windows operating system. On all other platforms, it returns the same value as AppDataLocation. This enum value was added in Qt 5.4.

QStandardPaths::AppConfigLocation

18

Returns a directory location where user-specific configuration files should be written. This is an application-specific directory, and the returned path is never empty. This enum value was added in Qt 5.5.

 

以上是关于Qt5.1.0怎么获取桌面路径的主要内容,如果未能解决你的问题,请参考以下文章

请问下Android里怎么获取桌面或系统里的某个Activity对象?

python获取当前路径

C#如何保证获取当前应用程序的绝对路径是对的?

java 获取桌面存储路径

C# 程序开机自动启动,但是获取当前路径名称是不正确,请教怎么解决?

Flutter 文件路径