[SOLVED] How to make QML plugin visible in Qt Quick Designer
-
I have created a few QML plugins. How can I make my QML components visible in the Qt Quick Designer? I have already create qmltyps and qmldir files and the components are recognized in the text editor.
EDIT: The answer is here: https://bugreports.qt-project.org/browse/QTCREATORBUG-12090#comment-241305
-
Here is the repository containing the plugins: https://github.com/strahlex/QtQuickVcp
The strange thing is local files QML files work as expected. They show up in the Qt Designer. However, imported modules do not except the ones that come Qt (like QtQuick.Controls). I have studied the code of QtQuickControls and found no special files declaring that they should show up as Qt Quick - Controls in Qt Creator. I am not sure this is built in with Qt Creator.
-
Okay lets make it simpler. I have created a new QtQuick 2 extension project:
pro file
@TEMPLATE = lib
TARGET = moduletest
QT += qml quick
CONFIG += qt pluginTARGET = $$qtLibraryTarget($$TARGET)
uri = com.mycompany.qmlcomponentsInput
SOURCES +=
moduletest_plugin.cpp
myitem.cppHEADERS +=
moduletest_plugin.h
myitem.hOTHER_FILES = qmldir
!equals(PRO_FILE_PWD, $$OUT_PWD) {
copy_qmldir.target = $$OUT_PWD/qmldir
copy_qmldir.depends = $$PRO_FILE_PWD/qmldir
copy_qmldir.commands = $(COPY_FILE) "$$replace(copy_qmldir.depends, /, $$QMAKE_DIR_SEP)" "$$replace(copy_qmldir.target, /, $$QMAKE_DIR_SEP)"
QMAKE_EXTRA_TARGETS += copy_qmldir
PRE_TARGETDEPS += $$copy_qmldir.target
}qmldir.files = qmldir
unix {
installPath = $$[QT_INSTALL_QML]/$$replace(uri, \., /)
qmldir.path = $$installPath
target.path = $$installPath
INSTALLS += target qmldir
}@
moduletest_plugin.h
@#ifndef MODULETEST_PLUGIN_H
#define MODULETEST_PLUGIN_H#include <QQmlExtensionPlugin>
class ModuletestPlugin : public QQmlExtensionPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")public:
void registerTypes(const char *uri);
};#endif // MODULETEST_PLUGIN_H
@
moduletest_plugin.cpp
@#include "moduletest_plugin.h"
#include "myitem.h"#include <qqml.h>
void ModuletestPlugin::registerTypes(const char *uri)
{
// @uri com.mycompany.qmlcomponents
qmlRegisterType<MyItem>(uri, 1, 0, "MyItem");
}
@myitem.h
@#ifndef MYITEM_H
#define MYITEM_H#include <QQuickItem>
class MyItem : public QQuickItem
{
Q_OBJECT
Q_DISABLE_COPY(MyItem)public:
MyItem(QQuickItem *parent = 0);
~MyItem();
};#endif // MYITEM_H
@myitem.cpp
@#include "myitem.h"MyItem::MyItem(QQuickItem *parent):
QQuickItem(parent)
{
// By default, QQuickItem does not draw anything. If you subclass
// QQuickItem to create a visual item, you will need to uncomment the
// following line and re-implement updatePaintNode()setFlag(ItemHasContents, true);
}
MyItem::~MyItem()
{
}@qmldir
@module com.mycompany.qmlcomponents
plugin moduletest@import
@import com.mycompany.qmlcomponents 1.0 as Test
@Is recognized but does not show up in Qt Designer
-
I have packaged all necessary stuff into a repo and filed a bug report:
https://github.com/strahlex/QMLExtensionBug -
I found out how to do this the QtQuick.Controls way. You need to write a Qt Quick Designer plugin. Take a look at https://github.com/strahlex/QtQuickVcp/tree/master/qmldesigner/machinekitplugin if you are interested.