Plugin type not recognized
-
Hi,
I am trying to build a simple plugin with multiple components Button, Checkbox etc. But When I try to use this plugin library in an application I get error "Widget is not a Type". Also please help with importing the plugin correctly.Thank you,
Ashwin -
Here is the file https://easyupload.io/fd9c5b
-
@RadiumBall Please show the code where you load and use the plug-in.
"Widget is not a Type" - this means that Widget is not known to the compiler - did you forget to include the header file where Widget is declared? -
@jsulm Thank you very much.
Here is my button widgetimport QtQuick 2.12 import QtQuick.Controls 2.12 Button { id: button /** sets Button Text visible*/ property bool bIsButtonTextVisible: true ....
Here is my CheckBox Widget
import QtQuick 2.0 import QtQuick.Controls 2.12 Rectangle{ id :checkBox /** checkbox current state checked / unchecked */ property bool checked: true ...
Here is my cpp code
#include "widgets_plugin.h" #include <qqml.h> void WidgetsPlugin::registerTypes(const char *uri) { // @uri com.mycompany.qmlcomponents qmlRegisterType(QUrl("qrc:/EDSButton/Source/component/ButtonWidget.qml"), uri, 1, 0, "ButtonWidget"); qmlRegisterType(QUrl("qrc:/EDSCheckBox/Source/component/CheckBoxWidget.qml"), uri, 1, 0, "CheckBoxWidget"); }
Here is my header file
#ifndef WIDGETS_PLUGIN_H #define WIDGETS_PLUGIN_H #include <QQmlExtensionPlugin> class WidgetsPlugin : public QQmlExtensionPlugin { Q_OBJECT Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid) public: void registerTypes(const char *uri) override; }; #endif // WIDGETS_PLUGIN_H
All this packaged into a library.
Here is my application cpp
#include <QGuiApplication> #include <QQmlApplicationEngine> int main(int argc, char *argv[]) { QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QGuiApplication app(argc, argv); QQmlApplicationEngine engine; const QUrl url(QStringLiteral("qrc:/main.qml")); QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, &app, [url](QObject *obj, const QUrl &objUrl) { if (!obj && url == objUrl) QCoreApplication::exit(-1); }, Qt::QueuedConnection); engine.load(url); return app.exec(); }
And here is my main qml
import QtQuick 2.9 import QtQuick.Window 2.2 //import "qrc:/EDSCheckBox/Source/component" import "C:\Users\RadiumBall\Downloads\EDSCheckBoxComponent\EDS_Component\debug\Widgets.dll" Window { width: 640 height: 480 visible: true title: qsTr("Hello World") CheckBoxWidget{ id : testCheckBox rCheckboxConfigureHeight: 24 rCheckboxConfigureWidth: 24 rCheckboxConfigureRadius: 1 rCheckboxConfigureImgHeight: 16 rCheckboxConfigureImgWidth: 16 sCheckBoxLabel: "CheckBox" }
I am doing two mistakes here, one is w.r.t importing the library and other complier throws me error 'CheckBoxWidget' is not a type.
PS: The CheckBoxWidget qml works perfectly fine when included directly but fails when included as a library.
Please help.