PDA

View Full Version : The plugin [path] uses incompatible Qt Library (4.8.2.) [Debug] (or [Release])



alitoh
30th July 2012, 17:33
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

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();
QVBoxLayout * m_layout;
QLabel * m_label;

private:
bool initialized;
};

#endif // NEWTESTPLUGIN_H


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 = new QVBoxLayout();
m_layout->addWidget(m_label);
setLayout(m_layout);
}

void NewTestPlugin::popUp()
{
this->show();
}

Q_EXPORT_PLUGIN2(NewTestPlugin, NewTestPlugin)


This is how I try to load it:


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);
}
}
}

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.

amleto
30th July 2012, 17:49
do you have other versions of qt on your machine?

what version is the plugin built with?
what version is the main app built with?

alitoh
30th July 2012, 18:22
The only version installed right now is 4.8.2 built with VS2010.
I used to have 4.8.2 precompiled for VS2008, but deleted it shortly after to move onto VS2010.

Both plugin and app are built in 4.8.2

alitoh
30th July 2012, 22:11
UPDATE I Don't know what I did, but the error changed from the previous one to this:

The file: [Path to dll].dll is not a valid Qt Plugin.

Anyone with an appropiate insigth on this issue?
Also, which is the difference between projects Qt4 Designer Plugin and Qt Library?

alitoh
31st July 2012, 13:00
Could the .pro file (or lack of a .pro file, to be exact) be the issue here? When I created the project in visual studio 2010, it did not provide me with one.

Is there a way to automatically generate one? Or at least a plugin .pro file's template?

alitoh
31st July 2012, 19:17
It's been pointed out by a friend of mine that the question might not only be unclear, but it might even be misleading, so I will rewrite it here (because I am unable to edit original post)

I am trying to compile a Qt Library Project to use its DLL as a plugin of my Main Application.
I've come across this particular error and I cannot seem to get past it, no matter what I try.

I believe cluttering the question with code tags is pointless when I can just provide you with the "working issue" (for lack of better wording).

[This is a link to both projects. The main application AND the plugin I am currently testing on.] (http://www.mediafire.com/?f7afqcgj3v6x5fz)

(please remember to modify the path in the Application project of the dll. I am using absolute path, which will most likely never be the same one you will use. I used absolute paths to make sure the problem was unrelated to finding the file itself)

So far I've checked:

* My Qt version is, indeed, 4.8.2. Built with VS2010 Command Prompt.
* As far as I understood the documentation, my code (particularly the APlugin project) follows the documentation instructions word by word. There's some space for human error, but I believe I got it right. [as specified here(The Lower-Level API: Extending Qt Applications)] (http://doc.qt.nokia.com/4.7-snapshot/plugins-howto.html)
* I am able to generate other QPluginLoader::errorString() errors (for example, using an invalid path to the .dll file will return a "file not found" error). Thus diminishing the margin of error in its use.

As of today, Google results are, at best, cryptic and/or do not apply to my current context of development (I am on VS2010, Win7 N Ultimate, Qt 4.8.2)

I believe it's better that I provided projects where the issue is reproducible, instead of just cluttering the question with code, but if you think I still should copy-paste my code, let me know and I will provide it explicitely in the question.

The only thing I am able to provide so far is that, albet I don't use a .pro file, I shouldn't need it, because my application will be windows exclusive, and the vcproj file already contains that data.

amleto
31st July 2012, 20:35
worked for me but I checked a couple of settings and changed them before trying 'as supplied'.

If you check the properties of generated files in debug/release (the moc_ files) you will see:

For debug config, the debug file does not have any property set for 'exclude from build', whereas the release file has 'exclude from build' set to 'yes'.

I just made sure the debug moc file has 'no' in that setting (for all moc files...).


After I built both solutions with that change the plugin was loaded fine.

I used studio 11 beta with studio 10 tools (studio 10 compilers etc.).


e:
win7 64 home prof.
Qt: 4.6.0 (built with msvc2010 using msvc2008 makespecs)