Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QPluginLoader Mac OS X Crashes
Forum Updated to NodeBB v4.3 + New Features

QPluginLoader Mac OS X Crashes

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 1.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jrch2k10
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • S Offline
      S Offline
      stevenceuppens
      wrote on last edited by
      #2

      Hey,

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

      Steven CEUPPENS
      Developer / Architect
      Mobile: +32 479 65 93 10

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jrch2k10
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • J Offline
          J Offline
          jrch2k10
          wrote on last edited by
          #4

          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
          {
          public:
          static T* Instance() {
          if(!m_pInstance) m_pInstance = new T;
          assert(m_pInstance != NULL);
          return m_pInstance;
          }
          protected:
          Singleton();
          ~Singleton();
          private:
          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
          {
          public:
          pluginsFactory(void);
          ~pluginsFactory(void);
          void loadPlugins(const QString &);
          INTERFACE* plugin(const quint64 &) const;
          private:
          QMap<quint64, INTERFACE*> mapInterface;
          };
          }

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

          template <class INTERFACE> pluginsFactory<INTERFACE>::~pluginsFactory(){
          mapInterface.clear();
          }

          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();
          if(plugin){
          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
          {
          public:
          #ifdef gnu_linux //visual studio don't seems to like pure virtual destructors
          virtual ~logInterface(void) = 0;
          #endif
          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)
          @

          main.cpp
          @ QString temp;
          temp.append("../Plugins/");
          Plugins::Instance()->loadPlugins(temp);
          qDebug() << Plugins::Instance()->plugin(0x55)->version();@

          the plugin.h
          @class ExampleInterfacePlugin : public QObject, myInterface
          {
          Q_OBJECT
          Q_PLUGIN_METADATA(IID myInterface_iid FILE "test.json")
          Q_INTERFACES(myInterface)
          public:
          myInterfacePlugin(void);
          ~myInterfacePlugin(void){internalStringOperator.clear();}
          QString description(void) const;
          quint64 identifier(void) const;
          quint16 version(void) const;
          private:

          QString internalStringOperator;
          

          };
          }@

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

          1 Reply Last reply
          0
          • J Offline
            J Offline
            jrch2k10
            wrote on last edited by
            #5

            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)@

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved