QT 创建、修改桌面快捷方式,固定任务栏快捷方式

一、获取系统文件路径

我们用到DesktopLocationAppDataLocation
QT 创建、修改桌面快捷方式,固定任务栏快捷方式_第1张图片

二、创建与修改快捷方式路径

修改可以直接将创建的快捷方式覆盖到指定的路径中即可。
(1)桌面快捷方式

QString deskTopPath = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
deskTopPath = deskTopPath + "/wechat.lnk";
QString srcFile = "D:/wechat.exe";
QFile::link(srcFile, taskBarPath);

(2)固定任务栏快捷方式(window10)

//1.拼接任务栏路径
QString taskBarPath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
int index = taskBarPath.lastIndexOf("/");
taskBarPath = taskBarPath.mid(0, index + 1) + "Microsoft/Internet Explorer/Quick Launch/User Pinned/TaskBar/" + "wechat.lnk";
//2.向指定路径创建快捷方式
QString srcFile = "D:/wechat.exe";
QFile::link(srcFile, taskBarPath);

在这里插入图片描述
在这里插入图片描述

你可能感兴趣的:(QT)