Qt could not find the platform plugin cocoa
-
Hi and welcome to devnet,
One thing you can do is start your application with the
QT_DEBUG_PLUGINS
environment variable set to 1 to see what happens with the plugin. -
@SGaist : Thanks for your reply.
If I set QT_DEBUG_PLUGINS to 1 it's stil not working. But I'm getting another error too:
QFactoryLoader::QFactoryLoader() checking directory path "/Users/ABC/Documents/Qt-Test/build-Debug/Qt-Test.app/Contents/MacOS/platforms" ...
-
It's not to make things go better, it's to help diagnose why plugin's loading fails.
Can you show the lines regarding the cocoa plugin ?
-
Also you can check if your Qt 5.11 installed still has a the plugins folder intact, because that's where Qt points your app to pickup the cocoa plugin.
You can check the path of that folder, it's stored in the .exe file, open a Terminal, cd to "/Users/ABC/Documents/Qt-Test/build-Debug/Qt-Test.app/Contents/MacOS" and type:
otool -l Qt-Test
(Look for the last LC_RPATH entry, should say something like /Users/ABC/Qt/5.11.3/clang_64/lib)
-
@SGaist Yeah, OK. That makes sense. But that's the only output I'm getting with QtCreator:
21:21:49: Starte /Users/ABC/Documents/Qt-Test/build-Debug/Qt-Test.app/Contents/MacOS/Qt-Test... QFactoryLoader::QFactoryLoader() checking directory path "/Users/ABC/Documents/Qt-Test/build-Debug/Qt-Test.app/Contents/MacOS/platforms" ... qt.qpa.plugin: Could not find the Qt platform plugin "cocoa" in "" This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem. 21:21:49: Das Programm ist abgestürzt. 21:21:49: Der Prozess wurde gestoppt. 21:21:49: /Users/ABC/Documents/Qt-Test/build-Debug/Qt-Test.app/Contents/MacOS/Qt-Test ist abgestürzt.
@hskoglund The last LC_RPATH shows /Library/Qt/5.11.3/clang64/lib. Generally that should be fine, because /Library/Qt is the location where I've installed Qt. Or am I wrong?
Thanks for the help to both of you so far!
-
Do you have a
qt.conf
file somewhere ? -
Hi, that last LC_RPATH entry would normally be "/Users/ABC/Qt/5.11.3/clang/lib" (because you'd most likely install Qt in your home directory). So your problem might be because of this, say you installed Qt in your home directory and later moved it to /Library/Qt.
Usually no problem, the Qt .dlls will still load fine and so would any application that you run macdeployqt on. But apps that you try to run from Qt Creator would fail, because the Qt5Core dll is "burned"/"branded" during the installation of Qt to where to original plugin directory is.
You can verify where the Qt5Core dll points to by doing
strings /Library/Qt/5.11.3/clang_64/lib/QtCore.framework/QtCore_debug | grep qt_prfxpath
If it points to /Users/ABC/Qt then either you need to binary patch the dll to the correct location or remember to run macdeployqt on your app after compilation (because macdeployqt "unbrands" that entry) -
@SGaist Do you mean in my project? Then no, there isn't any qt.conf. I've searched on my whole system and the only results of qt.conf are found within the directory /Library/Qt/ (in different subdirectories).
@hskoglund I've installed Qt on /Library/Qt and didn't moved it later. But the path which is stored in qt_prfxpath is really strange. The strings command shows the following output for qt_prfxpath: /Users/qt/work/install
I've created a qt.conf file in /Users/ABC/Documents/Qt-Test/build-Debug/Qt-Test.app/Contents/Resources with the correct prefix path /Library/Qt/5.11.3/clang_64 and now the app works fine.
Now to my question: Should I reinstall Qt? Maybe something wen't wrong during the installation? And should I install it on the "default" path within the user directory? Could it be the reason for my problem, because I installed Qt on /Library/Qt?
-
I would indeed re-install Qt to ensure that everything is working fine with a default install.
-
Thanks again to both of you.
I have finally resolved my issue by reinstalling Qt and rebuild my project. It seems that Qt shouldn't be installed outside of the user directory.
-
@LightDeveloper It's fine to install Qt outside your user directory, however, once you install it, do not manually move it elsewhere. Use the installer to specify the location where it is to be installed to.