28

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

3 Answers 3

46

If you are on Mac, go to the Terminal and paste the following:

pip3 install opencv-python-headless

The Qt platform plugin requires this library to be installed.

Thanks!

5
  • 2
    I would like to test some of the experimental features such as "cv2.aruco", which are not found in opencv-python-headless. Also trying to run on Visual Studio Code Feb 25, 2020 at 16:08
  • 3
    This solution worked like a charm on MacOS Mojave (10.14.6) running Python 3.7.7. Many thanks!
    – b.sodhi
    Mar 19, 2020 at 14:38
  • Thanks! @b.sodhi
    – Rudra shah
    Apr 19, 2021 at 16:09
  • I wonder why you need to use Python to add the library?... Aug 20, 2022 at 17:45
  • As it is a cross platform library, I found python method easy than using any other language like C++, perl etc...
    – Rudra shah
    Aug 21, 2022 at 21:03
15

Try setting QT_QPA_PLATFORM_PLUGIN_PATH to the plugin directory of where you installed qt.

E.g. if QT is installed in /Users/ABC/qt, then export QT_QPA_PLATFORM_PLUGIN_PATH=/Users/ABC/qt/plugins likely fixes your problem (did it for me on my brew installed qt).

5
  • @HayoBaan Thanks, man, it works as expected for Homebrew'ed QT and gnuplot. In my case (Homebrew in user home directory) it was export QT_QPA_PLATFORM_PLUGIN_PATH=~/homebrew/opt/qt/plugins that solved the problem. May 14, 2019 at 14:50
  • Hm. That works for sure, at least once you figure out the path for your Mac, but... this is not something that can be demanded from end-users installing the app! Isn't there a way for the app to automatically locate the missing plugin and load it? Aug 21, 2022 at 9:15
  • Sorry about my last comment, I was confusing 'local runs' with 'deployment' (using macdeployqt). Anyway, is there a way to automate this step, even for local runs? Aug 21, 2022 at 10:06
  • @GwynethLlewelyn I have absolutely no experience with deploying QT-applications, but if you deploy your app, isn't QT bundled with it? If so, you'll know the path so you can automatically set this in the applications run script, right?
    – Hayo Baan
    Aug 21, 2022 at 17:29
  • +1 However I compiled Qt from src, and it wanted plugins/platforms instead. (Apple Silicon, Ventura, Qt6) Sep 16 at 0:41
3

I've posted the same question a few days ago on the official Qt forum, because I haven't got a response here on Stackoverflow: https://forum.qt.io/topic/98816/qt-could-not-find-the-platform-plugin-cocoa

The problem seems to be that I've installed Qt on /Library/Qt (outside of the user directory). After reinstalling Qt to /Users/ABC/Qt and a complete rebuild of my project everything seems to work now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.