Problem with plugins
Page |
1 |
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!
19 replies
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
- ^
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?
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(int border_size READ border_size WRITE setBorderSize)
- public:
- Elipse(QDeclarativeItem *parent = 0);
- ~Elipse();
- int border_size() const;
- void setBorderSize(const int &border_size);
- 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:
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)
- {
- }
- Elipse::~Elipse() {}
- int Elipse::border_size() const { return m_border_size; }
- void Elipse::setBorderSize(const int &border_size) { m_border_size = border_size; }
- {
- painter->setBrush(m_color);
- painter->drawEllipse(boundingRect());
- }
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 ?
You must log in to post a reply. Not a member yet? Register here!





