Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Problem with plugins
Forum Updated to NodeBB v4.3 + New Features

Problem with plugins

Scheduled Pinned Locked Moved QML and Qt Quick
20 Posts 6 Posters 13.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kxyu
    wrote on 2 Dec 2010, 20:31 last edited by
    #6

    you should write

    @import "plugin"@

    1 Reply Last reply
    0
    • X Offline
      X Offline
      xsacha
      wrote on 3 Dec 2010, 00:02 last edited by
      #7

      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?

      • Sacha
      1 Reply Last reply
      0
      • P Offline
        P Offline
        puelocesar
        wrote on 6 Dec 2010, 11:17 last edited by
        #8

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

        I get this: Library import requires a version

        1 Reply Last reply
        0
        • P Offline
          P Offline
          puelocesar
          wrote on 6 Dec 2010, 11:57 last edited by
          #9

          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
          @

          1 Reply Last reply
          0
          • X Offline
            X Offline
            xsacha
            wrote on 6 Dec 2010, 14:11 last edited by
            #10

            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@

            • Sacha
            1 Reply Last reply
            0
            • P Offline
              P Offline
              puelocesar
              wrote on 6 Dec 2010, 14:22 last edited by
              #11

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

              1 Reply Last reply
              0
              • X Offline
                X Offline
                xsacha
                wrote on 6 Dec 2010, 14:27 last edited by
                #12

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

                • Sacha
                1 Reply Last reply
                0
                • B Offline
                  B Offline
                  baysmith
                  wrote on 6 Dec 2010, 16:48 last edited by
                  #13

                  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());
                  }
                  @

                  Nokia Certified Qt Specialist.

                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    jalomic
                    wrote on 10 Jan 2011, 12:10 last edited by
                    #14

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

                    1 Reply Last reply
                    0
                    • R Offline
                      R Offline
                      remy_david
                      wrote on 14 Sept 2011, 16:49 last edited by
                      #15

                      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 ?

                      1 Reply Last reply
                      0
                      • X Offline
                        X Offline
                        xsacha
                        wrote on 14 Sept 2011, 16:50 last edited by
                        #16

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

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

                        • Sacha
                        1 Reply Last reply
                        0
                        • R Offline
                          R Offline
                          remy_david
                          wrote on 14 Sept 2011, 17:09 last edited by
                          #17

                          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

                          1 Reply Last reply
                          0
                          • X Offline
                            X Offline
                            xsacha
                            wrote on 14 Sept 2011, 17:28 last edited by
                            #18

                            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.

                            • Sacha
                            1 Reply Last reply
                            0
                            • R Offline
                              R Offline
                              remy_david
                              wrote on 14 Sept 2011, 17:53 last edited by
                              #19

                              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 ?

                              1 Reply Last reply
                              0
                              • X Offline
                                X Offline
                                xsacha
                                wrote on 14 Sept 2011, 17:59 last edited by
                                #20

                                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.

                                • Sacha
                                1 Reply Last reply
                                0

                                • Login

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • Users
                                • Groups
                                • Search
                                • Get Qt Extensions
                                • Unsolved