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

岁小草 2013-04-15 05:02:08
如题,一个工程编译生成exe文件后,怎样创建一个exe的快捷方式到指定目录?
先谢过了!
...全文
1073 13 打赏 收藏 转发到动态 举报
AI 作业
写回复
用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

16,817

社区成员

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

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