Broken Qt 5.5 macdeployqt?
-
Is the Qt 5.5.0 macdeployqt command broken? When I run this...
# cd into my build directory macdeployqt example.app -dmg -always-overwrite
...I get an example.dmg. When I launch example.dmg and do the routine where I drag the example.app out of there to my Applications folder, and then run the application, it crashes with a long hexadecimal message. However, if I use the Finder and doubleclick the following path...
/Applications/example.app/Contents/MacOS/example
...it says...
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
Yet, here's the Cocoa plugin right here:
example.app/Contents/PlugIns/platforms/libqcocoa.dylib
What can I do to workaround a broken macdeployqt?
-
Hi, just tried doing a macdeployqt -dmg on a very simple Widgets app, dragging the app from the .dmg into the Applications folder and then launching it seems to work fine.
If you try doubleclicking/launching your app from inside your example.dmg, does that work?
-
@hskoglund I tried that against this project, but the same thing happened. Some things to note about this app:
QT += core gui sql widgets webkitwidgets
The OSX application is a widget-based application that loads the QWebView widget.
Okay, so then I took your suggestion. I tried a simple widget app. That worked well in a test. However, when I made the following changes, it broke again:
- In mainwindow.h, after the
#include <QApplication>
, add this line:
#include <QtWidgets>
This is a necessary library prerequisite for step #2.
- In main.cpp, before the
QApplication a(argc, argv);
, add this line:
QApplication::setStyle(QStyleFactory::create("Fusion"));
This will work when you run it in QtCreator, but fail with a cocoa error when you try to run a DMG after running it through macdeployqt command.
- In mainwindow.h, after the
-
@hskoglund Yep, problem localized to this line in my main.cpp:
QApplication::setStyle(QStyleFactory::create("Fusion"));
I took my larger project (the one that uses a webkit widget) and commented out that line. I then ran it through macdeployqt. At that point, it worked just fine. I add that line back, try all over again, and it fails.
-
@hskoglund Evidently, it's a Qt quirk. Someone else found this problem and found the resolution:
Basically, the fix is to move the Fusion style line to come AFTER the
QApplication a(argc, argv);
line, not before it as some docs had suggested.Why this trips up Cocoa is anyone's guess.
-
Yes, Qt is kind of braindead :-) before
QApplication a(argc, argv);
not many things work; it tries to load the libqcocoa.dylib when you specify that Fusion setting line, and because you did it before the QApplication constructor, Qt hasn't found and read in qt.conf file (written by macdeployqt, it tells Qt where to find libqcocoa.dylib). That's why moving the Fusion setting after makes Qt much happier.P.S. Actually you can get around this error in another way than by moving the Fusion setting line: by copying the PlugIns folder (created by macdeployqt in example.app) and place it together with the .exe/ELF file (MacOs/example). Because then Qt can load the Cocoa plugin without having read any qt.conf file.