0

I am trying to install a C++/Qt/Qml program with CMake. I tried the IFW generator, but I'd rather stick to NSIS64. Setup install file is correctly generated, and program is correctly installed. But my installed Qt program crashes right away, because

qt.qpa.plugin: Could not find the Qt platform plugin "windows" in ""

It is an easy to solve problem when running the program from the command line: we just need to set QT_QPA_PLATFORM_PLUGIN_PATH to the current directory (I installed/copied qwindows.dll there).

It is strange that the .exe does not look into the current program directory for Qt plugins. Anyways, a way to solve my problem would be: how to set an environment variable in a shortcut .lnk (created by NSIS)?

I have tried a bunch of things with NSIS (added in NSIS.template.in):

  CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\@CPACK_NSIS_DISPLAY_NAME@.lnk" "QT_QPA_PLATFORM_PLUGING_PATH=$INSTDIR\bin $INSTDIR\bin\@CPACK_NSIS_DISPLAY_NAME@.exe"

  CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\@CPACK_NSIS_DISPLAY_NAME@_cmd.lnk" \
  "C:\Windows\System32\cmd.exe" "/c SET QT_QPA_PLATFORM_PLUGING_PATH=$INSTDIR\bin && start $INSTDIR\bin\@CPACK_NSIS_DISPLAY_NAME@.exe"

but this does not compile. Maybe there is a different way to achieve this. Even if that would work, I would like to avoid setting QT_QPA_PLATFORM_PLUGING_PATH globally during the install, if possible, and restrain it to the program launch.

NOTE: documentation says:

CreateShortcut "$SMPROGRAMS\My Company\My Program.lnk" "$INSTDIR\My Program.exe"
"some command line parameters" "$INSTDIR\My Program.exe" 2 SW_SHOWNORMAL
ALT|CONTROL|SHIFT|F5 "a description"

but I am not too sure about how to use this in my case.

PJ127
  • 986
  • 13
  • 23
  • 1
    I pack the platform plugins in my NSIS installer and have them install in a platforms folder that is in the same folder as the executable. – drescherjm Apr 28 '22 at 12:37
  • Thank you. I did not get it: where is your exe, in a `platforms` folder? along with all the dlls? and `qwindows.dll` too? Does it work? I thought we must set the `QT_QPA_PLATFORM_PLUGING_PATH ` variable anyway for the program to find the plugins. Are there other directories the .exe will look into? What do you mean by "pack my plugins in my NSIS installer"? – PJ127 Apr 28 '22 at 12:41
  • 1
    No. In the folder that contains my executable there is also a platforms folder + a few others like plugins and sqldrivers. In that platforms folder I have only the `qwindows.dll` file. I am not using qml. – drescherjm Apr 28 '22 at 12:43
  • Setting a variable in the shortcut is the wrong solution. Fix your .exe instead. – Anders Apr 28 '22 at 13:17
  • Thank you very much, it works! I did not know qt was looking into the `platforms` subdirectory. That was strange I had to set this env variable. – PJ127 Apr 28 '22 at 13:53
  • Related: [https://forum.qt.io/topic/77497/where-to-put-the-platform-plugin-folder](https://forum.qt.io/topic/77497/where-to-put-the-platform-plugin-folder) and [https://wiki.qt.io/Deploy_an_Application_on_Windows](https://wiki.qt.io/Deploy_an_Application_on_Windows) – drescherjm Apr 28 '22 at 13:55

0 Answers0