Strange error : "error loading plugin. The specified module could not be found"
qt
Solution
Are you sure that your plugin is exporting the correct interface using the Q_INTERFACES() macro? If you get the error you have two possible things to check:
1) loader.instance() returns 0: in that case you have to investigate on the reported error.
2) qobject_cast returns 0: in that case I suppose that the problem is in the missing exported interface.
Also, you should consider that both of your execution paths are executing the same code, so maybe you're not getting an error at all... I'm referring to this:
if (i == NULL )
// Reports the error
QMessageBox::information(0, "this", "error loading plugin." + loader.errorString());
else
// Hey!? WTF!? Repots the error anyway!?
QMessageBox::information(0, "this", "error loading plugin." + loader.errorString());
3) I was forgetting: also check if both the plugin and the application are being built in the same way (debug/release).
4) By the way, another thing that should be checked is if the plugin carries some dependency (other dynamic libraries, for example). It happened to me once and I spent quite some time before figuring out that I was missing a DLL and that was preventing my plugin to load correctly!
Problem
I try to load my plugin using this code : ``` QString path = QFileDialog::getOpenFileName(0); QPluginLoader loader(path); AnprPluginInterface *i = qobject_cast< AnprPluginInterface* >(loader.instance()); if (i == NULL ) QMessageBox::information(0, "this", "error loading plugin." + loader.errorString()); else QMessageBox::information(0, "this", "plugin loaded."); ``` I send the absolute path of plugin to `QPluginLoader` but it says that can't find the plugin ! Error is : ``` error loading plugin. "Cannot load library The specified module could not be found." ```