Important: Please read the Qt Code of Conduct -

Qt could not find the platform plugin cocoa

  • I'm experimenting a little bit with Qt. I have successfully written a small app which works fine on my Windows 8.1 Laptop. Now I installed Xcode and Qt and copied the project folder to my MacBook. The application compiles fine on my Mac but when I wan't to run it via Qt Creator I'm getting the following errors:

    [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. Reinstall application may fix this problem.

    I have read that the tool macdeployqt is needed when I want to deploy the app to other PCs. But shouldn't my application run without macdeployqt when I execute it directly with the Qt Creator?

    I'm using MacOS X 10.14 with Qt 5.11.3. Xcode 10 and the MacOS X SDK 10.13 is installed and setted up correctly (at least it compiles with this SDK and without any error).

    Does anyone has an idea?

  • Lifetime Qt Champion

    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/" ...

  • Lifetime Qt Champion

    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/" 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/
    QFactoryLoader::QFactoryLoader() checking directory path "/Users/ABC/Documents/Qt-Test/build-Debug/" ...
    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/ 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!

  • Lifetime Qt Champion

    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/ 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?

  • Lifetime Qt Champion

    I would indeed re-install Qt to ensure that everything is working fine with a default install.

  • I agree with @SGaist, try to reinstall.
    That .../work/install prefix path is the contents of an unbranded/unpatched Qt5Core dll, so it’s a symptom of an interrupted installation.

  • 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.

Log in to reply