QML module: consuming in an executable vs in a shared library
-
I'm confused about something. I have a QML module "BCControls" that gets consumed by an application (executable). In the executable's main.cpp, I do the suggested:
#include <QtQml/qqmlextensionplugin.h> Q_IMPORT_QML_PLUGIN(BCControlsPlugin);
The QML within this application can see and use the QML types from the BCControls module without issue.
There are also plugin applications that are shared libraries that get brought in to this executable via QPluginLoader. These shared libraries have QML within that use the types defined in BCControls. These shared libraries get loaded and can use the QML types from the BCControls module despite not using the same:
#include <QtQml/qqmlextensionplugin.h> Q_IMPORT_QML_PLUGIN(BCControlsPlugin);
that the application uses. I don't even have to link against the BCControls static library in these shared libraries for the types to be found. In fact, if I add the Q_IMPORT_QML_PLUGIN I get a linker error that looks like this:
error LNK2019: unresolved external symbol "struct QStaticPlugin const __cdecl qt_static_plugin_BCControlsPlugin(void)" (?qt_static_plugin_BCControlsPlugin@@YA?BUQStaticPlugin@@XZ) referenced in function "public: __thiscall StaticBCControlsPluginPluginInstance::StaticBCControlsPluginPluginInstance(void)" (??0StaticBCControlsPluginPluginInstance@@QAE@XZ)
Q1: Why would I have this error with the shared library and not with the executable?
Q2: How would I make it so the shared library could link against the QML module so that it didn't depend on the executable making the QML types available (assuming that is really what's happening)?