Greeting
I created plugin with Qt (5.6.2) and trying to load it but it returns null all the time. I checked several question and also tried the solutions but it didn't work for me.
Can you take a look of the following code and see whats wrong?
DeviceManager.hpp
	
	- #ifndef DEVICE_MANAGER_HPP 
- #define DEVICE_MANAGER_HPP 
-   
- #include <QtCore> 
- #include <string> 
-   
- using namespace std; 
-   
- class DeviceManager 
- { 
-   
- public: 
-     virtual ~DeviceManager() {} 
-   
-     virtual bool initialize() = 0; 
-     virtual string getBrandName() = 0; 
-   
- }; 
-   
- QT_BEGIN_NAMESPACE 
- Q_DECLARE_INTERFACE(DeviceManager, "com.some.address/1.0") 
- QT_END_NAMESPACE 
-   
- #endif //DEVICE_MANAGER_HPP 
        #ifndef DEVICE_MANAGER_HPP
#define DEVICE_MANAGER_HPP
#include <QtCore>
#include <string>
using namespace std;
class DeviceManager
{
public:
    virtual ~DeviceManager() {}
    virtual bool initialize() = 0;
    virtual string getBrandName() = 0;
};
QT_BEGIN_NAMESPACE
Q_DECLARE_INTERFACE(DeviceManager, "com.some.address/1.0")
QT_END_NAMESPACE
#endif //DEVICE_MANAGER_HPP
To copy to clipboard, switch view to plain text mode 
  
DeviceManagerImpl.hpp
	
	- #ifndef DEVICE_MANAGER_IMPL_HPP 
- #define DEVICE_MANAGER_IMPL_HPP 
-   
- #include "DeviceManager.hpp" 
-   
- #include <string> 
- using namespace std; 
-   
- class DeviceManagerImpl  : public QObject- ,  public-  DeviceManager 
- { 
-     Q_OBJECT 
-     Q_PLUGIN_METADATA(IID "com.some.address/1.0") 
-     Q_INTERFACES(DeviceManager) 
-   
- public: 
-     DeviceManagerImpl(); 
-   
-     //Override Method 
-     bool initialize();          //Have implementation in cpp file 
-     string getBrandName();      //Have implementation in cpp file 
-   
- private: 
-     ... 
-   
- }; 
-   
- #endif //DEVICE_MANAGER_IMPL_HPP 
        #ifndef DEVICE_MANAGER_IMPL_HPP
#define DEVICE_MANAGER_IMPL_HPP
#include "DeviceManager.hpp"
#include <string>
using namespace std;
class DeviceManagerImpl : public QObject, public DeviceManager
{
    Q_OBJECT
    Q_PLUGIN_METADATA(IID "com.some.address/1.0")
    Q_INTERFACES(DeviceManager)
public:
    DeviceManagerImpl();
    //Override Method
    bool initialize();          //Have implementation in cpp file
    string getBrandName();      //Have implementation in cpp file
private:
    ...
};
#endif //DEVICE_MANAGER_IMPL_HPP
To copy to clipboard, switch view to plain text mode 
  
Pro File
	
	- QT       += core gui sql 
-   
- TARGET = Device-Manager 
- #TARGET = $$qtLibraryTarget(Device-Manager) 
- TEMPLATE = lib 
- CONFIG += plugin 
-   
-   
- SOURCES += \ 
-     ... 
-   
- HEADERS += \ 
-     ... 
-   
- DISTFILES += Device-Manager.json 
-   
- unix { 
-     target.path = /usr/lib 
-     INSTALLS += target 
- } 
        QT       += core gui sql
TARGET = Device-Manager
#TARGET = $$qtLibraryTarget(Device-Manager)
TEMPLATE = lib
CONFIG += plugin
SOURCES += \
    ...
HEADERS += \
    ...
DISTFILES += Device-Manager.json
unix {
    target.path = /usr/lib
    INSTALLS += target
}
To copy to clipboard, switch view to plain text mode 
  
And this is how i try to load the plugin in my main process.
	
	- QObject *-  plugin  =-  pluginLoader -- >instance ()- ; 
 
-   
- if (plugin) 
- { 
-     deviceManager = qobject_cast<DeviceMAnager *>(plugin); 
-     return true; 
- } 
- else 
- { 
-     delete pluginLoader; 
-     return false; 
- } 
        QPluginLoader * pluginLoader = new QPluginLoader(pluginPath.c_str());
QObject * plugin = pluginLoader->instance();
if (plugin)
{
    deviceManager = qobject_cast<DeviceMAnager *>(plugin);
    return true;
}
else
{
    delete pluginLoader;
    return false;
}
To copy to clipboard, switch view to plain text mode 
  
Im using QT 5.6.2 and QT Creator and MinGW 32bit.
Thanks in advance.
				
			
Bookmarks