How to use plugins?



  • Hello!
    I have build qmlextensionplugins example (TimeExample) and run it with qmlscene and it works fine.
    There are @qmlqtimeexampleplugin.dll qmlqtimeexampleplugin.lib qmldir@

    files in folder
    @D:/Qt/Qt5.2.0_directx/5.2.0/msvc2010/examples/qml/qmlextensionplugins/imports/TimeExample@
    And now I try to use this plugin in my app but have some problems.

    I have created new Qt Qiuck appliction project & add to .pro file this sting
    @LIBS += -LD:/Qt/Qt5.2.0_directx/5.2.0/msvc2010/examples/qml/qmlextensionplugins/imports/TimeExample -lqmlqtimeexampleplugin@
    Then I add "import TimeExample 1.0" into main.qml file but QtCreator underlines it with red ((
    Project builds without errors but has errors when runs:
    /MyClock/main.qml:3:1: module "TimeExample" is not installed import TimeExample 1.0

    I want to use C++ type "Time" and QML type "Clock" from qmlqtimeexampleplugin in my app.
    What i need to do?



  • read "this":Identified Modules



  • Hi,

    Let me told you how I work with plugins in my apps. I've create a plugin and complete it to application folder. I'll try to show you step-by-step:

    1. Copy you plugin file to folder with you client app.
    2. Open client app and import you plugin. It's may looks like:
      @
      import <plugin_name> <version>
      @

    In my case it looks like:
    @
    import com.shav.msl 1.0
    @

    The you can add your class(es) to application qml file(s).

    Also you may check paths to plugins using this:
    @
    QML_IMPORT_TRACE=1
    @

    This build option you must set to you client app build environment settings. Open your project in QtCreator and select project settings tab from the left side. Find "Build Environment" section and press to add button.

    After load your client app in application console you must see all qml plugins and file which was loaded. Also you must see paths to your plugin in client app.

    Also you can check this links:
    See the section on debugging imports from:
    http://qt-project.org/doc/qt-5.0/qtquick/qtquick-debugging.html

    For more information on importing modules, see the docs about creating identified (installed) QML modules:
    http://qt-project.org/doc/qt-5.0/qtqml/qtqml-modules-topic.html
    http://qt-project.org/doc/qt-5.0/qtqml/qtqml-modules-identifiedmodules.html
    http://qt-project.org/doc/qt-5.0/qtqml/qtqml-modules-cppplugins.html



  • Thanks ))
    I should have moved my plugins files to one folder with NAME of plugin & moved this folder to my app folder & build folder )

    But I have new question now.
    I have some QML files & some C++ classes in my plugin which I could use in QML.
    I want to share my plugin but i don't want to share my QML files only dlls.
    How can I do this?



  • Compile your QML files into a resource for your DLL.



  • I have added my file to resource in my plugin dll and set alias "MyQmlAlisas" but it doesn't work (
    Could you explain more detailed, please.



  • "it doesn't work" is rather vague, and my crystal ball it at the repair shop. Please be more specific.



  • Ok )

    I had taken Qt example "qmlextensionplugins" as a base and quite refactored it.
    I have created resource file "res.qrc" and added my QML files there (Clock.qml and make alias "Clock").
    Then I created new Qt Quick project and copied my plugin folder (with files qmlextensionplugins.dll, qmlqtimeexampleplugin.lib, qmldir) to folder "TimeExample" near app .pro file.
    In my app in QML I import my plugin: import TimeExample 1.0
    It's ok.
    I have C++ type in my plugin "Time" (see example) and QML type "Clock".
    I can use type "Time" in my app but I can't use "Clock" type ((
    I have an error: " bla-bla... MyClock/main.qml:24:5: Clock is not a type "



  • Could you please provide us your Clock.qml? I probably know what the problem could be.



  • Oh no, I've lain.
    I need to copy one more file: Clock.qml to folder with plugin.
    Because qmlrdir file contains such sting "Clock 1.0 Clock.qml"
    I want to remove this string and remove Clock.qml file from plugin folder and "insert" it to dll.

    Here is my Clock.qml:
    @import QtQuick 2.0

    Rectangle {
    id: clock
    width: 200; height: 200; color: "gray"

    property alias city: cityLabel.text
    property variant hours
    property variant minutes
    property variant shift : 0
    
    Image { id: background; source: "qrc:/imports/TimeExample/clock.png" }
    
    Image {
        x: 92.5; y: 27
        source: "qrc:/imports/TimeExample/hour.png"
        transform: Rotation {
            id: hourRotation
            origin.x: 7.5; origin.y: 73;
            angle: (clock.hours * 30) + (clock.minutes * 0.5)
            Behavior on angle {
                SpringAnimation{ spring: 2; damping: 0.2; modulus: 360 }
            }
        }
    }
    
    Image {
        x: 93.5; y: 17
        source: "qrc:/imports/TimeExample/minute.png"
        transform: Rotation {
            id: minuteRotation
            origin.x: 6.5; origin.y: 83;
            angle: clock.minutes * 6
            Behavior on angle {
                SpringAnimation{ spring: 2; damping: 0.2; modulus: 360 }
            }
        }
    }
    
    Image {
        anchors.centerIn: background; source: "qrc:/imports/TimeExample/center.png"
    }
    
    Text {
        id: cityLabel; font.bold: true; font.pixelSize: 14; y:200; color: "white"
        anchors.horizontalCenter: parent.horizontalCenter
    }
    

    }
    @

    Here is res.qrc of plugin:
    @<RCC>
    <qresource prefix="/">
    <file>plugins.qml</file>
    <file alias="Clock">imports/TimeExample/Clock.qml</file>
    <file>imports/TimeExample/center.png</file>
    <file>imports/TimeExample/clock.png</file>
    <file>imports/TimeExample/hour.png</file>
    <file>imports/TimeExample/minute.png</file>
    <file>imports/TimeExample/qmldir</file>
    </qresource>
    </RCC>@


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.