Problem with plugins



  • How do I use plugins? I created one, folowing the example on "Chapter 5: Writing an Extension Plugin", but it's not working! I'm getting the following error when I try to run my main.qml:

    @ElipsePlugin/main.qml:7:5: Elipse is not a type
    Elipse {
    ^ @

    I have a qmldir on the same dir as main.qml:

    @plugin ElipsePlugin lib@

    I also have a lib folder with the following files: libelipseplugin.a e elipseplugin.dll

    Other question, I created a project with a elipse plugin. But I want to use this plugin on another project. How to do that? I thought I should just put the plugin's dll on a lib folder, and then write a qmldir declaring the plugin, but that didn't worked!



  • try putting qmldir with "plugin ElipsePlugin" into plugon directory and importing directory in qml file



  • How?

    I tried renaming the 'lib' folder to 'plugin' as you said, changed the qmldir as you said, and added this to main.qml:

    @import plugin 1.0@

    Now I'm getting this:

    @main.qml:2:1: module "plugin" is not installed
    import plugin 1.0

     ^ @


  • By the way, this isn't working either:

    @import Qt 4.7
    import ElipsePlugin 1.0

    Rectangle {
    width: 100
    height: 62

    Elipse {
        color: "red"
    }
    

    }
    @

    @Prototipacao/fontes/ElipsePlugin/main.qml:2:1: module "ElipsePlugin" is not installed
    import ElipsePlugin 1.0

     ^ @


  • Perhaps you need to tell the qmlviewer the path to your module with one of the command-line options:

    @ -I <directory> ........................... prepend to the module import search path,
    display path if <directory> is empty
    -P <directory> ........................... prepend to the plugin search path
    @



  • you should write

    @import "plugin"@



  • In my docs it is 'Chapter 6: Writing an Extension Plugin' so I hope you have the latest docs.

    Anyway if you use a plugin as you intended, you will not need an 'import' line.
    The qmldir should take care of this. The qmldir should be in the same directory though. Is this where it is?

    If it's still not working, you may not have defined the Elipse type correctly.
    Check
    qmlRegisterType<Elipse>("ElipsePlugin, 1, 0, "Elipse");
    or
    Q_EXPORT_PLUGIN2(elipseplugin, ElipsePlugin);

    If this still doesn't work, can you test if you are able to run the Chapter 6 example unmodified?



  • [quote author="Kxyu" date="1291321905"]you should write
    @import "plugin"@[/quote]

    I get this: Library import requires a version



  • I just can't make it to work.. It's identical to Chapter 5: Writing an Extension Plugin (that works here), but my code isn't working... Here is all the code:

    My elipseplugin.h:

    @#ifndef ELIPSEPLUGIN_PLUGIN_H
    #define ELIPSEPLUGIN_PLUGIN_H

    #include <QtDeclarative/QDeclarativeExtensionPlugin>

    class ElipsePlugin : public QDeclarativeExtensionPlugin
    {
    Q_OBJECT

    public:
    void registerTypes(const char *uri);
    };

    #endif // ELIPSEPLUGIN_PLUGIN_H

    @

    My elipseplugin.cpp:

    @#include "elipseplugin.h"
    #include "elipse.h"

    #include <QtDeclarative/qdeclarative.h>

    void ElipsePlugin::registerTypes(const char *uri)
    {
    qmlRegisterType<Elipse>(uri, 1, 0, "Elipse");
    }

    Q_EXPORT_PLUGIN2(elipseplugin, ElipsePlugin)
    @

    My elipse.h:
    @#ifndef ELIPSE_H
    #define ELIPSE_H

    #include <QtDeclarative/QDeclarativeItem>

    class Elipse : public QDeclarativeItem
    {
    Q_OBJECT
    Q_DISABLE_COPY(Elipse)

    Q_PROPERTY(QColor color READ color WRITE setColor)
    Q_PROPERTY(QColor border_color READ border_color WRITE setBorderColor)
    Q_PROPERTY(int border_size READ border_size WRITE setBorderSize)
    

    public:
    Elipse(QDeclarativeItem *parent = 0);
    ~Elipse();

    QColor color() const;
    void setColor(const QColor &color);
    
    QColor border_color() const;
    void setBorderColor(const QColor &border_color);
    
    int border_size() const;
    void setBorderSize(const int &border_size);
    
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
    

    private:
    QColor m_color;
    QColor m_border_color;
    int m_border_size;
    };

    QML_DECLARE_TYPE(Elipse)

    #endif // ELIPSE_H
    @

    My qmldir:

    @plugin elipseplugin lib@

    My main.qml:
    @import Qt 4.7

    Rectangle {
    width: 100
    height: 62

    Elipse {
        color: "red"
    }
    

    }
    @

    My elipseplugin.pro:

    @ TEMPLATE = lib
    CONFIG += qt plugin
    QT += declarative

    DESTDIR = lib
    OBJECTS_DIR = tmp
    MOC_DIR = tmp

    Input

    SOURCES +=
    elipse.cpp
    elipseplugin.cpp

    HEADERS +=
    elipse.h
    elipseplugin.h

    OTHER_FILES = qmldir
    main.qml
    @



  • Which part isn't working? Still the QML?

    How are you running the QML file? QMLViewer?

    Does your directory look like this?
    @
    .
    ..
    app.qml
    qmldir
    lib\elipseplugin.dll
    @
    P.S. Won't change anything but should be using (new notation):
    @import QtQuick 1.0@



  • Yes, the file structure is like you said, and I'm running with QMLViewer, but the plugin from the examples works fine with QMLViewer.



  • Do you remember what you changed?
    You could try running a diff between your directory and the original plugin.



  • You didn't provide the implementation of Elipse (elipse.cpp), but a common mistake (at least for me) is clearing the QGraphicsItem::ItemHasNoContents flag which is set by QDeclarativeItem.

    Works for me with the files above, plus these:

    main.qml
    @
    import Qt 4.7

    Rectangle {
    width: 100
    height: 62

    Elipse {
        anchors.fill: parent
        color: "red"
    }
    

    }
    @

    elipse.cpp
    @
    #include "elipse.h"

    #include <QtGui/QPainter>

    Elipse::Elipse(QDeclarativeItem *parent) :
    QDeclarativeItem(parent)
    {
    setFlag(QGraphicsItem::ItemHasNoContents, false);
    }

    Elipse::~Elipse() {}

    QColor Elipse::color() const { return m_color; }
    void Elipse::setColor(const QColor &color) { m_color = color; }

    QColor Elipse::border_color() const { return m_border_color; }
    void Elipse::setBorderColor(const QColor &border_color) { m_border_color = border_color; }

    int Elipse::border_size() const { return m_border_size; }
    void Elipse::setBorderSize(const int &border_size) { m_border_size = border_size; }

    void Elipse::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
    {
    painter->setPen(QPen(m_border_color, m_border_size));
    painter->setBrush(m_color);
    painter->drawEllipse(boundingRect());
    }
    @



  • I have same trouble. Can anybody tell me stap-by-stap "howto" ?



  • I have the same troubles.
    For me the main problem is to understand how to correctly import the plugin to the application.

    If the plugin is in another location than the application, how do you tell the build system were to look ?
    Since I have several targets (simulator, device...) + release (debug, release...), I have different version of my plugin library in different folders. How does the build system makes the difference ?



  • In your .pro you can specify it depending on target and other such variables.

    symbian: { ...}
    win32: { ... }



  • I know what you mean, however if I understand the docs correctly, importing a plugin does not involve the .pro at all
    From the docs, the only thing you have to do is to add "import MyPlugin 1.0" at the top of the QML file in which you want to use the plugin.
    http://doc.qt.nokia.com/latest/qdeclarativeextensionplugin.html



  • Your .pro is basically a shell script where you can configure which files are used. From the .pro you can effectively specify which plugin will be MyPlugin.



  • This is mentionned nowhere in the docs about using plugins, nor in the QMake doc. There don't seems to have any command related to QML Plugins in QMake.
    Would you mind beeing a little bit more specific ?



  • In your .pro, you can specify source files to compile (eg. symbian: { ... HEADERS+=myplugin.h .. }, you can specify plugins to add (eg. symbian: { folder_01.source = symbian/plugin \ folder_01.target = symbian \ DEPLOYMENTFOLDERS = folder_01 }) and so on.

    I mean that you can change the file structure with your .pro which will affect which plugin you import. I believe this is generally how multiple platforms are handled.

    Otherwise, you can have defines for Q_WS_XX in source code or even entirely different QML files for each platform.
    #ifdef Q_WS_S60
    v.setMainQML("qrc:/symbian.qml");
    #endif

    There's many choices.


Log in to reply
 

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