Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt5 cannot find platform plugins Mac OS X

Tags:

c++

macos

qt

I am trying to deploy a Qt program on Mac according to this link. After going through with otool -L on my executable and all of the libraries that it depends on, which I copied into the application bundle, I get this error in QtCreator's application output when I try to run it.

This application failed to start because it could not find or load the Qt platform plugin "cocoa".

Reinstalling the application may fix this problem. The program has unexpectedly finished.

I've tried copying the qt platform plugins libqcocoa.dylib and changing the plugins directory in qt.conf, according to this, but it still fails.

Also worth pointing out, I first tried to use qt's macdeployqt tool, but it fails with this message, despite being the first time I run it on the executable:

ERROR: Could not find bundle binary for "MyProgram.app/Contents/MacOS/MyProgram" ERROR: "otool: can't open file: (No such file or directory)"

WARNING:

WARNING: Could not find any external Qt frameworks to deploy in "MyProgram.app/Contents/MacOS/MyProgram"

WARNING: Perhaps macdeployqt was already used on "MyProgram.app/Contents/MacOS/MyProgram" ?

WARNING: If so, you will need to rebuild "MyProgram.app/Contents/MacOS/MyProgram" before trying again. ERROR: Could not find bundle binary for "MyProgram.app/Contents/MacOS/MyProgram"

ERROR: file copy failed from "/Developer/Applications/Qt/plugins/platforms/libqcocoa.dylib"

ERROR: to "MyProgram.app/Contents/MacOS/MyProgram/Contents/PlugIns/platforms/libqcocoa.dylib"

ERROR: file copy failed from "/Developer/Applications/Qt/plugins/printsupport/libcocoaprintersupport.dylib"

ERROR: to "MyProgram.app/Contents/MacOS/GraphiteMiniEditor/Contents/PlugIns/printsupport/libcocoaprintersupport.dylib"

like image 641
Paul Musgrave Avatar asked Nov 14 '13 20:11

Paul Musgrave


2 Answers

To give Kamil Klimek's solution some more attention (It solved the problem for me):

I had the same problem when I installed QtCreator (Qt 5.x) with the offline installer, but apparently also had Qt (4.x) installed through Homebrew (probably pulled in as a dependency). Compiling the code with 5.x, and deploying it with the 4.x macdeployqt script doesn't work.

So, make sure that e.g.:

which macdeployqt

calls macdeployqt from the same Qt version / path used to compile the code.

like image 101
Bart Avatar answered Nov 15 '22 14:11

Bart


Re macdeployqt fails: it seems like, for the argument to macdeployqt you are passing the path to the executable instead of the path to the bundle. I.e. just pass .../MyProgram.app instead of .../MyProgram.app/Contents/MacOS/MyProgram.

(But I am also unable to get it find libqcocoa, in a sandboxed app. I may resort to linking that statically into my app.)

like image 29
bootchk Avatar answered Nov 15 '22 15:11

bootchk