0

I have a 2 qml files in a lib and I want to export those to another project and was unable to import in my QuickQmlTest project. I want to use those qml files from QmlPlugin lib in QuickQmlTest project. Is there any additional step I need to do ? I have a folder structure

  QMLProject  
  |-- QmlPlugin -(it is lib)
      |--QML  
         |--CustomButton.qml
         |-- CustomPolygon.qml
  |-- QuickQmlTest - (app)   

My QmPlugins.pro looks like this

TEMPLATE = lib
TARGET = QmlPlugin
QT += qml quick
CONFIG += plugin c++11

TARGET = $$qtLibraryTarget($$TARGET)


HEADERS += \
    MyPlugin.h

DISTFILES = qmldir \  
    CustomButton.qml \
    CustomPolygon.qml
DESTDIR = $$PWD/lib

And I linked the generated dlls into to the QuickQmlTest.pro using

LIBS += -L$$PWD/../QmlPlugin/lib -lQmlPlugin  
INCLUDEPATH += $$PWD/../QmlPlugin

MyPlugin.h

    #include <QQmlExtensionPlugin>
    #include <QtQml/qqml.h>
    class MyItemModel: public QObject
    {
       Q_OBJECT
       Q_PROPERTY(qreal roundingRadius READ roundingRadius WRITE setRoundingRadius)
        public:
        void setRoundingRadius(const qreal rounding)
        {
            roundingRadius_ = rounding;
        }
         qreal roundingRadius() const
         {
             return roundingRadius_;
         }
         private:
         qreal roundingRadius_{8.0};
    };
    class MyPlugin : public QQmlExtensionPlugin
    {
        Q_OBJECT
        Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid)
        public:
        void registerTypes(const char* uri)override
        {
            Q_ASSERT(uri == QLatin1String("Components"));
            qmlRegisterType<MyItemModel>(uri, 1, 0, "MyItemModel");
        }
    };

in qmldir I have

module Components
Components 1.0 CustomButton.qml CustomPolygon.qml
plugin QmlPlugin

In the QuickQmlTest (app)
I want to use CustomButton.qml and CustomPolygon.qml in my main.qml
So my main.qml in QuickQmlTest app

import QtQuick 2.9
import QtQuick.Window 2.2
import QtQuick.Controls 1.4
import Components 1.0 //To import the dll from lib 
Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")
    CustomPolygon
    {
     width:60
     height:30  
    }
    CustomButton
    {
     width:60
     height:30  
    }
}  

And also I want to see my Custom qml types(CustomButton and CustomPolygon) in Quick Design mode which I am unable to achieve.

Rubina
  • 123
  • 1
  • 17
  • show your MyPlugin,h – eyllanesc Jan 03 '19 at 21:57
  • added .h details in the description – Rubina Jan 03 '19 at 22:29
  • The easiest way to return custom component from a plugin is to use some factory method ie. you pass name of the component and receive QQuickItem-derived class. Btw, if you call in your app to regusterTypes the component should be visible in the QML code. – folibis Jan 04 '19 at 08:39
  • @folibis Could you show an example how to achieve this ? – Rubina Jan 04 '19 at 14:03
  • That depends on what you want to archive. Show the code where you instantiate the plugin. – folibis Jan 04 '19 at 14:50
  • I updated the description to include my QuickQmlTest . I am not sure if I need to copy the qml plugins dll to some Qt directory to see the plugins . – Rubina Jan 04 '19 at 15:32

0 Answers0