0

I want to create a link to a file using the QFile::link() method. It works with files without any argument, but now I need to link to an .exe file with arguments.

QFile(qApp->applicationFilePath()).link(QDir().homePath() + QString("/Desktop/AppArg.lnk"))

My problem is that I can't set any arguments in the destination path.

I've tried:

QFile(qApp->applicationFilePath() + " argument").link(QDir().homePath() + QString("/Desktop/AppArg.lnk"))

The shortcut looks like this:

that

but it should look like this:

that

Is there any way to create a link / shortcut with arguments?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Bamp
  • 25
  • 5
  • Related but old: [https://stackoverflow.com/questions/14401404/qt-win-creating-app-shortcuts](https://stackoverflow.com/questions/14401404/qt-win-creating-app-shortcuts) Not sure if there is any current Qt support. – drescherjm Feb 09 '22 at 19:45
  • You may have to resort to this: [https://stackoverflow.com/questions/3906974/how-to-programmatically-create-a-shortcut-using-win32](https://stackoverflow.com/questions/3906974/how-to-programmatically-create-a-shortcut-using-win32) – drescherjm Feb 09 '22 at 19:48
  • 1
    Don't bother with `Qt::link()` for this. [Use `IShellLink` directly](https://learn.microsoft.com/en-us/windows/win32/shell/links) instead, so you can call its [`SetPath()`](https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ishelllinkw-setpath) and [`SetArguments()`](https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ishelllinkw-setarguments) methods separately. – Remy Lebeau Feb 09 '22 at 19:49

0 Answers0