Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Qt5.8: plugin loaded before main() is entered
I am migrating from Qt4.8.7 to Qt5.8.0, on Mac OS X El Capitan.
I am building a program for binary deployment, so in the application bundle I put executables into "Contents/MacOS", plugins into "Contents/plugins", and dylibs into "Contents/lib". I then run through all files in those three directories changing the location of every non-system dylib they load to "@executable_path/../lib/...". In the code, as soon as main() is entered I create a QApplication and add both lib and plugins to the library path. This way my users do not need to install Qt, it comes in my application bundle.
That worked for Qt4.
But with Qt5 it is loading the plugin "platforms/libqcocoa" BEFORE main() is entered. So I have no opportunity to set the library path to my bundle. On my build machine it finds it where HomeBrew installed it, which brings in the HomeBrew versions of QtGUI and QtCore, crashing the program because there are now two copies of those dylibs.
How is this supposed to work????
Loading a plugin before main() seems like a fundamental problem.
Can you show exactly how you are starting your application ?
Note that you are currently not following macOS standards for the content of your bundle.
Qt also comes now with macdeployqt that simplifies the deployment of application, you might want to check that also.
I now see I was mistaken, and the plugin is indeed loaded after main() is entered. So I can resolve it. My apologies.
In case anyone cares, the resolution was to move calls to QCoreApplication::addLibraryPath() to before the QApplication is created. Qt4.8.7 did not care but Qt5.8 does.