Important: Please read the Qt Code of Conduct -

MacOS deploying styles

  • Hi, I've compiled the qtstyleplugins under qt5.0.0 osx. It works only without deploying libraries into the app bundle (macdeployqt).
    If I try to run the app:
    @Class NotificationReceiver is implemented in both /app-bundle-path.../QtWidgets and /qt-abs-path/QtWidgets. One of the two will be used. Which is undefined.
    Abort trap@

    otool -L

    • All qt-libraries are located under @executable_path/../Frameworks - no absolute path...

    Is it possible to deploy qtstyleplugins inside the app-bundle?

    Thanks for help.

  • Lifetime Qt Champion


    Check that your executable and other dependencies also have their path updated (even Qt libraries to be sure)

  • The problem is probably not with qtstyleplugins.
    My program:
    @int main(int argc, char *argv[]) {
    QApplication app(argc, argv);@

    The style "xxx" doesn't exist, this application runs in default osx style - without deploying. After deploying it shows the error above...
    otool -L for every library (including executable) in the bundle returns correct paths (@executable_path)

  • Lifetime Qt Champion

    Did you check what QStyleFactory::keys() returns ?

  • No custom style used:

    @#include "mainwindow.h"
    #include <QApplication>
    #include <qstylefactory.h>
    #include <qdebug.h>

    int main(int argc, char *argv[])
    qDebug() << QStyleFactory::keys();

    QApplication a(argc, argv);
    MainWindow w;;
    return a.exec&#40;&#41;;


    ("Windows", "Fusion", "Macintosh")
    objc[2880]: Class NotificationReceiver is implemented in both /Users/martin.dusek/cpp/teststyle-build-5_0_0_x64-Release/ and /usr/local/qt-5.0.0/x64/lib/QtWidgets.framework/Versions/5/QtWidgets. One of the two will be used. Which one is undefined.
    QObject::moveToThread: Current thread (0x102712a10) is not the object's thread (0x102719830).
    Cannot move to target thread (0x102712a10)

    On Mac OS X, you might be loading two sets of Qt binaries into the same process. Check that all plugins are compiled against the right Qt binaries. Export DYLD_PRINT_LIBRARIES=1 and check that only one set of binaries are being loaded.
    Failed to load platform plugin "cocoa". Available platforms are:

    Abort trap

    Without deploying:
    (“Windows”, “Fusion”, “Macintosh”)

    • no crash

    Deployed + commented out this line:
    @//qDebug() << QStyleFactory::keys();@

    • no crash

    It looks like that any touch to QStyle in OSX = crash :(

  • Lifetime Qt Champion

    The error message you get tells you that not all your libs/exec are linked against the same Qt which means that at least one of your dependencies has not the proper paths set (have you also the plugins in the bundle ? Did you "otool" them ?)

  • All dependencies are prefixed with @executable_path. It is really strange...

  • Lifetime Qt Champion

    For all Qt libraries ?

  • yes.

    This is OK:
    @QApplication a(argc, argv);
    qDebug() << QStyleFactory::keys();@

    This crashes:
    @qDebug() << QStyleFactory::keys();
    QApplication a(argc, argv);@

  • @QApplication a(argc, argv);

    There is a hint in qt-docs - QApplication::setStyle
    To ensure that the application's style is set correctly, it is best to call this function before the QApplication constructor, if possible.

    This is impossible on mac...

  • Lifetime Qt Champion

    Time to use
    @#ifdef Q_OS_MACX@

    unless it's a mac only app

Log in to reply