Qt在程序中创建一个exe的快捷方式到指定位置

岁小草 2013-04-15 05:02:08
如题,一个工程编译生成exe文件后,怎样创建一个exe的快捷方式到指定目录?
先谢过了!
...全文
944 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
shmiloveyou 2015-12-21
  • 打赏
  • 举报
回复
引用 11 楼 mingxia_sui 的回复:
[quote=引用 5 楼 zengcccc 的回复:] bool QFile::link ( const QString & linkName ) Creates a link named linkName that points to the file currently specified by fileName(). What a link is depends on the underlying filesy……
不好意思,我还有个问题:在双击一个快捷方式的时候,能不能获取到该快捷方式的名称或是路径?[/quote] 可以试下这个成员函数: QString QFile::symLinkTarget ( const QString & fileName ) [static] Returns the absolute path of the file or directory referred to by the symlink (or shortcut on Windows) specified by fileName, or returns an empty string if the fileName does not correspond to a symbolic link. This name may not represent an existing file; it is only a string. QFile::exists() returns true if the symlink points to an existing file. This function was introduced in Qt 4.2. QString QFile::symLinkTarget () const This is an overloaded function. Returns the absolute path of the file or directory a symlink (or shortcut on Windows) points to, or a an empty string if the object isn't a symbolic link. This name may not represent an existing file; it is only a string. QFile::exists() returns true if the symlink points to an existing file. This function was introduced in Qt 4.2. See also fileName() and setFileName().
shmiloveyou 2015-12-21
  • 打赏
  • 举报
回复
引用于 Qt4.8 manual

bool QFile::link ( const QString & linkName )

Creates a link named linkName that points to the file currently specified by fileName(). What a link is depends on the underlying filesystem (be it a shortcut on Windows or a symbolic link on Unix). Returns true if successful; otherwise returns false.
This function will not overwrite an already existing entity in the file system; in this case, link() will return false and set error() to return RenameError.
Note: To create a valid link on Windows, linkName must have a .lnk file extension.
Note: Symbian filesystem does not support links.
See also setFileName().

bool QFile::link ( const QString & fileName, const QString & linkName ) [static]

This is an overloaded function.
Creates a link named linkName that points to the file fileName. What a link is depends on the underlying filesystem (be it a shortcut on Windows or a symbolic link on Unix). Returns true if successful; otherwise returns false.

See also link().
补充:创建文件夹的快捷方式到指定路径(下例为桌面)

    //注意第一个参数指定文件夹的路径,第二个参数指定快捷方式放置的路径以及新名称,记得一定要加.lnk后缀
    bool ret = QFile::link(QString("./Serialization"),QString("C:/Users/Administrator/Desktop/Serialization.lnk"));
    if(!ret){
        qDebug("error");
    }
亲测,成功!
zengcccc 2013-04-16
  • 打赏
  • 举报
回复
引用 7 楼 mingxia_sui 的回复:
引用 5 楼 zengcccc 的回复:bool QFile::link ( const QString & linkName ) Creates a link named linkName that points to the file currently specified by fileName(). What a link is depends ……
完全可以 , 注意一下中文路径 还有空格 还有连接的后缀名 是 .lnk
岁小草 2013-04-16
  • 打赏
  • 举报
回复
引用 5 楼 zengcccc 的回复:
bool QFile::link ( const QString & linkName ) Creates a link named linkName that points to the file currently specified by fileName(). What a link is depends on the underlying filesy……
我试了一下,没有任何效果,请问你有这样的例子吗?可不可以给我看下。
zengcccc 2013-04-16
  • 打赏
  • 举报
回复
bool QFile::link ( const QString & linkName ) Creates a link named linkName that points to the file currently specified by fileName(). What a link is depends on the underlying filesystem (be it a shortcut on Windows or a symbolic link on Unix). Returns true if successful; otherwise returns false. This function will not overwrite an already existing entity in the file system; in this case, link() will return false and set error() to return RenameError. Note: To create a valid link on Windows, linkName must have a .lnk file extension. Note: Symbian filesystem does not support links. See also setFileName().
岁小草 2013-04-16
  • 打赏
  • 举报
回复
引用 5 楼 zengcccc 的回复:
bool QFile::link ( const QString & linkName ) Creates a link named linkName that points to the file currently specified by fileName(). What a link is depends on the underlying filesy……
不好意思,我还有个问题:在双击一个快捷方式的时候,能不能获取到该快捷方式的名称或是路径?
岁小草 2013-04-16
  • 打赏
  • 举报
回复
引用 9 楼 mingxia_sui 的回复:
引用 8 楼 zengcccc 的回复:引用 7 楼 mingxia_sui 的回复:引用 5 楼 zengcccc 的回复:bool QFile::link ( const QString & linkName ) Creates a link named linkName that points to the file current……
不好意思,是我弄错了,可以显示图标。
岁小草 2013-04-16
  • 打赏
  • 举报
回复
引用 8 楼 zengcccc 的回复:
引用 7 楼 mingxia_sui 的回复:引用 5 楼 zengcccc 的回复:bool QFile::link ( const QString & linkName ) Creates a link named linkName that points to the file currently specified by fileName……
嗯,这样是可以了,多谢。 还有个问题,创建的快捷方式并没有把图片一起加上,请问一下怎么给快捷方式设置图片呢?
岁小草 2013-04-15
  • 打赏
  • 举报
回复
引用 3 楼 heksn 的回复:
Qt没有这个功能
啊 不会吧,那c或c++呢?
  • 打赏
  • 举报
回复
Qt没有这个功能
岁小草 2013-04-15
  • 打赏
  • 举报
回复
引用 1 楼 cerci0304 的回复:
啥意思?右键发送到桌面快捷方式不就可以了么~~ 要打成安装包的话用installsheild
嗯,如果是通过代码实现快捷方式呢?
微雨流光 2013-04-15
  • 打赏
  • 举报
回复
啥意思?右键发送到桌面快捷方式不就可以了么~~ 要打成安装包的话用installsheild
网管教程 从入门到精通软件篇 ★一。★详细的xp修复控制台命令和用法!!! 放入xp(2000)的光盘,安装时候选R,修复! Windows XP(包括 Windows 2000)的控制台命令是在系统出现一些意外情况下的一种非常有效的诊断和测试以及恢复系统功能的工具。小编的确一直都想把这方面的命令做个总结,这次辛苦老范给我们整理了这份实用的秘笈。   Bootcfg   bootcfg 命令启动配置和故障恢复(对于大多数计算机,即 boot.ini 文件)。   含有下列参数的 bootcfg 命令仅在使用故障恢复控制台时才可用。可在命令提示符下使用带有不同参数的 bootcfg 命令。   用法:   bootcfg /default  设置默认引导项。   bootcfg /add    向引导列表添加 Windows 安装。   bootcfg /rebuild  重复全部 Windows 安装过程并允许用户选择要添加的内容。   注意:使用 bootcfg /rebuild 之前,应先通过 bootcfg /copy 命令备份 boot.ini 文件。   bootcfg /scan    扫描用于 Windows 安装的所有磁盘并显示结果。   注意:这些结果被静态存储,并用于本次会话。如果在本次会话期间磁盘配置发生变化,为获得更新的扫描,必须先重新启动计算机,然后再次扫描磁盘。   bootcfg /list   列出引导列表已有的条目。   bootcfg /disableredirect 在启动引导程序禁用重定向。   bootcfg /redirect [ PortBaudRrate] |[ useBiosSettings]   在启动引导程序通过指定配置启用重定向。   范例: bootcfg /redirect com1 115200 bootcfg /redirect useBiosSettings   hkdsk   创建并显示磁盘的状态报告。Chkdsk 命令还可列出并纠正磁盘上的错误。   含有下列参数的 chkdsk 命令仅在使用故障恢复控制台时才可用。可在命令提示符下使用带有不同参数的 chkdsk 命令。   vol [drive:] [ chkdsk [drive:] [/p] [/r]   参数  无   如果不带任何参数,chkdsk 将显示当前驱动器的磁盘状态。 drive: 指定要 chkdsk 检查的驱动器。 /p   即使驱动器不在 chkdsk 的检查范围内,也执行彻底检查。该参数不对驱动器做任何更改。 /r   找到坏扇区并恢复可读取的信息。隐含着 /p 参数。   注意 Chkdsk 命令需要 Autochk.exe 文件。如果不能在启动目录(默认为 %systemroot%System32)找到该文件,将试着在 Windows 安装 CD 找到它。如果有多引导系统的计算机,必须保证是在包含 Windows 的驱动器上使用该命令。 Diskpart   创建和删除硬盘驱动器上的分区。diskpart 命令仅在使用故障恢复控制台时才可用。   diskpart [ /add |/delete] [device_name |drive_name |partition_name] [size]   参数 无   如果不带任何参数,diskpart 命令将启动 diskpart 的 Windows 字符模式版本。   /add   创建新的分区。   /delete   删除现有分区。   device_name   要创建或删除分区的设备。设备名称可从 map 命令的输出获得。例如,设备名称:   DeviceHardDisk0   drive_name   以驱动器号表示的待删除分区。仅与 /delete 同时使用。以下是驱动器名称的范例:   D:   partition_name   以分区名称表示的待删除分区。可代替 drive_name 使用。仅与 /delete 同时使用。以下是分区名称的范例:   DeviceHardDisk0Partition1    大小   要创建的分区大小,以兆字节 (MB)表示。仅与 /add 同时使用。   范例   下例将删除分区: diskpart /delete Device HardDisk0 Partition3 diskpart /delete F:   下例将在硬盘上添加一个 20 MB 的分区:   diskpart /add Device HardDisk0 20   Fixboot

16,211

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧