Your plugin project should have an include file like this:
// myplugin_global.h
#ifndef MYPLUGIN_GLOBAL_H
#define MYPLUGIN_GLOBAL_H
#include <QtCore/qglobal.h>
#ifdef MYPLUGIN_LIB
# define MYPLUGIN_EXPORT Q_DECL_EXPORT
#else
# define MYPLUGIN_EXPORT Q_DECL_IMPORT
#endif
#endif // MYPLUGIN_GLOBAL_H
// myplugin_global.h
#ifndef MYPLUGIN_GLOBAL_H
#define MYPLUGIN_GLOBAL_H
#include <QtCore/qglobal.h>
#ifdef MYPLUGIN_LIB
# define MYPLUGIN_EXPORT Q_DECL_EXPORT
#else
# define MYPLUGIN_EXPORT Q_DECL_IMPORT
#endif
#endif // MYPLUGIN_GLOBAL_H
To copy to clipboard, switch view to plain text mode
and each of the classes that you want to export from your plugin DLL should be declared this way:
#ifndef MYPLUGIN_H
#define MYPLUGIN_H
#include <QObject>
#include <QtPlugin>
#include <IMyPlugin.h> // defines pure virtual interfaces implemented by MyPlugin
#include "myplugin_global.h"
class MYPLUGIN_EXPORT MyPlugin
, public IMyPlugin // the interface supported by your plugin class
{
Q_OBJECT;
Q_PLUGIN_METADATA( IID "com.MyCompany.IMyPlugin" );
Q_INTERFACES( IMyPlugin );
// ... constructor, destructor, and implementation of iMyPlugin virtual methods
};
#endif // MYPLUGIN_H
#ifndef MYPLUGIN_H
#define MYPLUGIN_H
#include <QObject>
#include <QtPlugin>
#include <IMyPlugin.h> // defines pure virtual interfaces implemented by MyPlugin
#include "myplugin_global.h"
class MYPLUGIN_EXPORT MyPlugin
: public QObject
, public IMyPlugin // the interface supported by your plugin class
{
Q_OBJECT;
Q_PLUGIN_METADATA( IID "com.MyCompany.IMyPlugin" );
Q_INTERFACES( IMyPlugin );
// ... constructor, destructor, and implementation of iMyPlugin virtual methods
};
#endif // MYPLUGIN_H
To copy to clipboard, switch view to plain text mode
Such classes compile and link into a DLL just fine in MSVC2012 on my system. I did have the experience with undefined externals, but this appears to be a glitch in MSVC. If you do a clean rebuild, I think they go away. It's been a long time, so I don't remember exactly what I did - I remember there was some mis-configuration, but I use vcxproj files, not .pro files.
You might also check to make sure that "MYPLUGIN_LIB" is defined when compiling your DLL, and not defined when you link your DLL as an ordinary (not dynamically loaded) DLL (by linking to the corresponding .LIB that defines the entry points that will be resolved at runtime)
Bookmarks