I am having this runtime error when trying to load a plugin with Qt's QPluginLoader.
I am on windows 7 N x64 and VS2010.
The error is:
The plugin '[absolute path to the .DLL file]/TestPlugin.dll' uses incompatible Qt library. (4.8.2) [debug]
Note that if I change build type to Release, the error shown is now
The plugin '[absolute path to the .DLL file]/TestPlugin.dll' uses incompatible Qt library. (4.8.2)
[release]
This is the test code I am using:
This is the Interface (it's both in the main app project and in the plugin project)
#ifndef NEWTESTPLUGIN_H
#define NEWTESTPLUGIN_H
class INewInterface
{
public
virtual ~INewInterface() {}
virtual void popUp() = 0;
};
Q_DECLARE_INTERFACE( INewInterface , "NewInterface")
#endif //NEWTESTPLUGIN_H
#ifndef NEWTESTPLUGIN_H
#define NEWTESTPLUGIN_H
class INewInterface
{
public
virtual ~INewInterface() {}
virtual void popUp() = 0;
};
Q_DECLARE_INTERFACE( INewInterface , "NewInterface")
#endif //NEWTESTPLUGIN_H
To copy to clipboard, switch view to plain text mode
My test plugin.h:
#ifndef NEWTESTPLUGIN_H
#define NEWTESTPLUGIN_H
#include "INewInterface.h"
#include "QtGui\\qwidget.h"
#include "QtGui\\qlabel.h"
#include "QtGui\\qboxlayout.h"
class NewTestPlugin
: public QWidget,
public INewInterface
{
Q_OBJECT
Q_INTERFACES(INewInterface)
public:
NewTestPlugin
(QObject *parent
= 0);
void popUp();
private:
bool initialized;
};
#endif // NEWTESTPLUGIN_H
#ifndef NEWTESTPLUGIN_H
#define NEWTESTPLUGIN_H
#include "INewInterface.h"
#include "QtGui\\qwidget.h"
#include "QtGui\\qlabel.h"
#include "QtGui\\qboxlayout.h"
class NewTestPlugin : public QWidget, public INewInterface
{
Q_OBJECT
Q_INTERFACES(INewInterface)
public:
NewTestPlugin(QObject *parent = 0);
void popUp();
QVBoxLayout * m_layout;
QLabel * m_label;
private:
bool initialized;
};
#endif // NEWTESTPLUGIN_H
To copy to clipboard, switch view to plain text mode
and .cpp
#include "customwidget.h"
#include <QtCore/QtPlugin>
#include "newtestplugin.h"
NewTestPlugin
::NewTestPlugin(QObject *parent
){
m_label
= new QLabel("ESTO ES UN PLUGIN!");
m_layout->addWidget(m_label);
setLayout(m_layout);
}
void NewTestPlugin::popUp()
{
this->show();
}
Q_EXPORT_PLUGIN2(NewTestPlugin, NewTestPlugin)
#include "customwidget.h"
#include <QtCore/QtPlugin>
#include "newtestplugin.h"
NewTestPlugin::NewTestPlugin(QObject *parent)
{
m_label = new QLabel("ESTO ES UN PLUGIN!");
m_layout = new QVBoxLayout();
m_layout->addWidget(m_label);
setLayout(m_layout);
}
void NewTestPlugin::popUp()
{
this->show();
}
Q_EXPORT_PLUGIN2(NewTestPlugin, NewTestPlugin)
To copy to clipboard, switch view to plain text mode
This is how I try to load it:
if(token==QXmlStreamReader::StartElement)
{
if(m_xmlRStream->name()=="Game")
{
QString textFromElement
= m_xmlRStream
->readElementText
();
button->setMinimumSize(150, 150);
m_mainLayout->addWidget(button);
//create a pluginLoader
QPluginLoader loader
("C:/Users/TestDllProject/Win32/Debug/TestPlugin.dll");
QObject * plugin
= loader.
instance();
if(plugin)
{
INewInterface* asd = qobject_cast<INewInterface*>(plugin);
asd->popUp();
}
else
{
pluginErrorMessageBox->information(this,"Error loading DLL","Requested DLL wasn't properly loaded.\n \n" + loader.errorString(), pluginErrorMessageBox->Ok);
QPluginLoader loader
("C:/Users/TestDllProject/Win32/Debug/NewTestPlugin.dll");
QObject * plugin
= loader.
instance();
if(plugin)
{
INewInterface* asd = qobject_cast<INewInterface*>(plugin);
asd->popUp();
}
else
{
pluginErrorMessageBox->information(this,"Error loading DLL","Requested DLL wasn't properly loaded.\n \n" + loader.errorString(), pluginErrorMessageBox->Ok);
exit(1);
}
}
}
if(token==QXmlStreamReader::StartElement)
{
if(m_xmlRStream->name()=="Game")
{
QString textFromElement = m_xmlRStream->readElementText();
QPushButton * button = new QPushButton(textFromElement, this);
button->setMinimumSize(150, 150);
m_mainLayout->addWidget(button);
//create a pluginLoader
QPluginLoader loader("C:/Users/TestDllProject/Win32/Debug/TestPlugin.dll");
QObject * plugin = loader.instance();
if(plugin)
{
INewInterface* asd = qobject_cast<INewInterface*>(plugin);
asd->popUp();
}
else
{
QMessageBox * pluginErrorMessageBox = new QMessageBox(this);
pluginErrorMessageBox->information(this,"Error loading DLL","Requested DLL wasn't properly loaded.\n \n" + loader.errorString(), pluginErrorMessageBox->Ok);
QPluginLoader loader("C:/Users/TestDllProject/Win32/Debug/NewTestPlugin.dll");
QObject * plugin = loader.instance();
if(plugin)
{
INewInterface* asd = qobject_cast<INewInterface*>(plugin);
asd->popUp();
}
else
{
pluginErrorMessageBox = new QMessageBox(this);
pluginErrorMessageBox->information(this,"Error loading DLL","Requested DLL wasn't properly loaded.\n \n" + loader.errorString(), pluginErrorMessageBox->Ok);
exit(1);
}
}
}
To copy to clipboard, switch view to plain text mode
I honestly dont know what I am doing wrong, and all google found out had mostly nothing to do with what I am doing.
I am using 4.8.2, for both the DLL and the .Exe (Also, they are both in the same solution).
Any help on the issue would be greately appreciated.
As always, if I am not providing appropiate info, please let me know what you need.
Thank you.
Bookmarks