Important: Please read the Qt Code of Conduct -

QPluginLoader Mac OS X Crashes

  • Hi guys, first im using Qt 5.2.1 for Mac OS X and my OS version is 10.9.2.

    ok im having a weird issue with plugins on Mac but i cannot debug it due it crashes lldb too but it basically works totally fine on linux and windows.

    Ok my code is a very simple plugins system using QpluginLoader class and a singleton class to insert in a QMap the resulting plugin pointer after calling instance and it works flawlessly on Linux and Windows using Clang/GCC and VS2012 but in Mac it crashes(plugin debuging show it even reads the metadata just fine) when QPluginLoader is loading the plugins(i thought at first it was my code crashing but simply return a Qstring crashes anyway) and when Qtcreator calls LLDB to inspect the QpluginLoader class it crashes too.

    is this common in Mac(due to platform restriction)? any tips to help me debug it(i dont wanna go to bugzilla and post "it crashes")?

    many thx in advance

  • Hey,

    I have the same environment, can your share your code to test? or warp up a minimum working example ?

  • sure, ill patch something together as an example later today, ty for your time ;)

  • my singleton class
    @#include <QPluginLoader>
    #include <QString>
    #include <QDir>

    #include <stddef.h> // defines NULL
    #include <assert.h>
    #include <QDebug>
    typedef Singleton<pluginsFactory <PluginInterface> > Plugin;

    template <class T>
    class Singleton
    static T* Instance() {
    if(!m_pInstance) m_pInstance = new T;
    assert(m_pInstance != NULL);
    return m_pInstance;
    Singleton(Singleton const&);
    Singleton& operator=(Singleton const&);
    static T* m_pInstance;

    template <class T> T* Singleton<T>::m_pInstance=NULL;

    template <class INTERFACE> class pluginsFactory
    void loadPlugins(const QString &);
    INTERFACE* plugin(const quint64 &) const;
    QMap<quint64, INTERFACE*> mapInterface;

    template <class INTERFACE> pluginsFactory<INTERFACE>::pluginsFactory(void){}

    template <class INTERFACE> pluginsFactory<INTERFACE>::~pluginsFactory(){

    template <class INTERFACE> void pluginsFactory<INTERFACE>::loadPlugins(const QString &internalPath){
    QDir dir(internalPath);
    foreach (QString fileName, dir.entryList(QDir::Files)) {
    QPluginLoader loader(dir.absoluteFilePath(fileName));
    QObject *plugin = loader.instance();
    INTERFACE * iLOG = qobject_cast< INTERFACE *>(plugin);
    mapInterface.insert(iLOG->identifier(), iLOG);

    template <class INTERFACE> INTERFACE* pluginsFactory<INTERFACE>::plugin(const quint64 &ID) const{
    return mapInterface.value(ID);

    MyInterface class
    @class myInterface
    #ifdef gnu_linux //visual studio don't seems to like pure virtual destructors
    virtual ~logInterface(void) = 0;
    virtual QString description(void) const = 0;
    virtual quint64 identifier(void) const = 0;
    virtual quint16 version(void) const = 0;
    virtual void onlyLocal(bool) = 0;

    #define plugInterface_iid "net.example.plugInterface"

    Q_DECLARE_INTERFACE(plugInterface, plugInterface_iid)

    @ QString temp;
    qDebug() << Plugins::Instance()->plugin(0x55)->version();@

    the plugin.h
    @class ExampleInterfacePlugin : public QObject, myInterface
    Q_PLUGIN_METADATA(IID myInterface_iid FILE "test.json")
    QString description(void) const;
    quint64 identifier(void) const;
    quint16 version(void) const;

    QString internalStringOperator;


    #define PLUGIN_VERSION=123456;
    @quint16 myInterfacePlugin::version(void) const{
    return PLUGIN_VERSION; //just any int for test

  • i got some glitches in the pasted code

    in plugin.cpp
    @ quint16 ExampleInterfacePlugin::version(void) const{
    return PLUGIN_VERSION; //just any int for test
    myinterface class
    @#define myInterface_iid "net.example.myInterface"
    Q_DECLARE_INTERFACE(myInterface, myInterface_iid)@

Log in to reply