Can't run OSX app created with macdeployqt. Missing Cocoa plugin when using Fusion style

Using Qt 5.5.0 C++, I made a very simple widget-based application example -- just a form with no buttons on it, going with defaults. If I compile it and run it through macdeployqt, then run the application out of the dmg file, it runs just fine. However, if I edit the main.cpp and add this line in...


...before the QApplication a(argc, argv); line...

...which of course requires that my mainwindow.h have an #include <QtWidgets> line, then run it through macdeployqt, I get the following error. (Actually, I get a crash, but when I open up the file and find the binary under, and run that, I get a terminal window that tells me the following message.)

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

Reinstalling the application may fix this problem.

Abort trap: 6

So, it's having trouble finding the cocoa plugin. However, I have the cocoa plugin in this path:

I imagine I need to use the otool and install_name_tool commands to fix something that's broke with macdeployqt, but don't know what the technique is.


Some blogs may mention adding the following style line BEFORE the QApplication a(argc, argv); line:


If you do that, Qt 5.5 will throw a Cocoa error and the application will crash when you try to deploy it via macdeployqt, but won't crash when running it in Qt Creator.

The fix is simple. The blogs are wrong -- put the style line AFTER the QApplication a(argc, argv); line, not before it. Now when you deploy through macdeployqt, the Cocoa crash problem goes away.

Need Your Help

Conventions for annotating appinfo in xml-schema?

xsd annotations

I believe the three below are syntactically correct; but which are permitted according to conventions (especially in the enterprise)?

Determining system requirements (hardware, processor & memory) for a batch based software application

c# .net batch-processing

I am tasked with building an application wherein the business users will be defining a number of rules for data manipulation &amp; processing (e.g. taking one numerical value and splitting it equa...