Solved .qmltypes not found by QtCreator for custom Qml Components
-
I'm having trouble getting the qmldir and the qmlplugindump / .qmltypes infrastructure to work in my QtCreator with Qt 5.12.3
I have a folder QmlResources that builds a library of the same name (CMake based).
Inside it there is a /qml folder containing a CustomButton.qml and a qmldir. Both are added to a qml.qrc located in the main folder. There is also a /src folder containing a class based on QQmlExtensionPlugin, so the result is/QmlResources CMakeLists.txt qml.qrc /qml/ CustomButton.qml qmldir /src/ QmlResources.h
The qml.qrc looks like this
<RCC> <qresource prefix="/QmlResources"> <file>qml/CustomButton.qml</file> <file>qml/qmldir</file> </qresource> </RCC>
qmldir:
module QmlResources CustomButton 0.1 CustomButton.qml plugin QmlResources
CustomButton.qml
import QtQuick 2.6 import QtQuick.Controls 1.4 Button { // some button stuff }
QmlResources.h
class CustomQmlResources final: public QQmlExtensionPlugin { Q_OBJECT Q_PLUGIN_METADATA(IID "somestring") public: CustomQmlResources (); void registerTypes(const char * uri) override { qmlRegisterType(QUrl("qrc:/QmlResources/qml/CustomButton.qml"), uri, MAJOR, MINOR, "CustomButton"); }; };
Now QtCreator is telling me when I import QmlResources 0.1 in a QML file:
"QML module does not contain information about components contained in plugins"
When I try to run "qmlplugindump.exe QmlResources 0.1" in the qml folder I get
QQmlComponent: Component is not ready file:///typelist.qml:3:1: module "QmlResources" is not installed
I've read all of the documentation about qmldirs and plugins multiple times and I can't figure out how this is supposed to work
-
I made some progress and I was able to generate a .qmltypes file.
Some issues I had to fix:- qml.qrc needed to be in the same folder as the qmls and qmldir so the path doesn't need /qml/
- The registerType has to use the now shorter url, eg qmlRegisterType(QUrl("qrc:/QmlResources/CustomButton.qml"), uri, MAJOR, MINOR, "CustomButton");
- With the cxx plugin it seems to be unnecessary adding the CustomButton to the qmldir. What needs to be there is "module QmlResources" and "plugin QmlResources"
- The qmlplugindump.exe needs to be run inside the release folder with the release.dlls, otherwise it won't find required dependencies, eg "/loaddependencies.qml:2:1: module "QtQuick" plugin "qtquick2plugin" not found"
After generating the .qmltypes file I added it to the /qml/ folder and put this in the qmldir "typeinfo qmlresources.qmltypes". Unfortunately it's still trying to auto generate and failing due to the QtQuick dependency it fails to find.
-
I got it to work! What was missing was installing the .qmltypes file into the build folder of QmlResources together with the qmldir, so both can be found by the QtCreator