Reputation: 195
I'm trying to wrap my head around QML plugins and I hope that someone can explain it to me because I seem to be missing something.
So I've gone ahead and created a Qt Quick 2 Extension Plugin. I have a simple source file, I've subclassed the QQmlExtensionPlugin class and registered the new type with qmlRegisterType. I've built this project and it gives me a DLL (I'm on Windows 7, and using QT 5.13). As I understand it, I should now be able to take this DLL and the qmldir file and drop into a new project and I should be able to load the QML from the DLL that is exposed via the qmldir file.
Unfortunately, when I do that, it doesn't work. All the examples I'm seeing online are showing a qml file that does an import of the plugin qml, but every time I try that, the import doesn't work and gives me a "QML module not found" error.
So my question is: How do I actually use the DLL and qmldir files in another project to expose the QML from the DLL to the new project?
Upvotes: 4
Views: 2560
Reputation: 136
It seems that you're missing the root QML import path.
The default root import path is %QTDIR%/qml
, you can simply copy&paste your plugin modules into this folder so that the QML engine can find and load it.
Or a more common practice, using QQmlEngine::addImportPath()
QQmlEngine engine;
engine.addImportPath(qApp->applicationDirPath() + "/qml");
Note that you should always use Module (Namespace) Imports
to import your C++ plugin module:
import My.CppModule 1.0
Using Directory Imports
to import a C++ plugin module is a Undefined Behavior currently:
import "My/CppModule" // Might fail
Upvotes: 6