Results 1 to 3 of 3

Thread: [Qt 4.6] Add a plugin to the QtDeclarative module

  1. #1
    Join Date
    Mar 2009
    Posts
    72
    Thanks
    7
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default [Qt 4.6] Add a plugin to the QtDeclarative module

    Hi, I've made a library with a couple of QObject-derived classes.

    I want to create a qml module to import in QML files (with the unique beta-release of QtDeclarative for Qt 4.6.0).

    I've used QML_DECLARE_TYPE and QML_DEFINE_TYPE to export my classes.

    myclass.h

    Qt Code:
    1. class MYLIBSHARED_EXPORT MyClass : public QObject
    2. {
    3. Q_OBJECT
    4.  
    5. Q_PROPERTY(bool checkable READ isCheckable WRITE setCheckable NOTIFY checkableChanged)
    6.  
    7. // ...
    8. };
    9.  
    10. QML_DECLARE_TYPE(MyClass)
    To copy to clipboard, switch view to plain text mode 

    myclass.cpp

    Qt Code:
    1. #include "myclass.h"
    2.  
    3. // ...
    4.  
    5. QML_DEFINE_TYPE(MyLibrary, 1,0, MyClass, MyClass)
    To copy to clipboard, switch view to plain text mode 

    mylibrary.pro

    Qt Code:
    1. QT += declarative
    2. TEMPLATE = lib
    3. DEFINES += MYLIBSHARED_LIBRARY
    4. HEADERS += myclass.h
    5. SOURCES += myclass.cpp
    To copy to clipboard, switch view to plain text mode 

    Now i want to link this library in another project and write something like this:

    example.qml

    Qt Code:
    1. import MyLibrary 1.0
    2.  
    3. MyClass {
    4. }
    To copy to clipboard, switch view to plain text mode 

    How can i do this?

    Thanks!

  2. #2
    Join Date
    Mar 2009
    Posts
    72
    Thanks
    7
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: [Qt 4.6] Add a plugin to the QtDeclarative module

    From the documentation:

    To use built-in types, you must import the module defining them. For example, to use types from Qt, import it:

    Qt Code:
    1. import Qt 4.6
    To copy to clipboard, switch view to plain text mode 

    This makes available all types in Qt that were available in Qt 4.6, regardless of the actual version of Qt executing the QML.

    Modules can be compiled-in (such as the Qt module), or they can be defined in QML files.
    I've compiled it in a dynamic library, now how can I link it to my executable?

  3. #3
    Join Date
    Mar 2009
    Posts
    72
    Thanks
    7
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: [Qt 4.6] Add a plugin to the QtDeclarative module

    The previous code is correct and works.

    My original problem was in the exported name of my class which must begin with a capital letter (i.e. MyClass).

Similar Threads

  1. Qt Svg Module
    By onurozcelik in forum Qt Programming
    Replies: 5
    Last Post: 14th March 2010, 06:47
  2. Qt4.6.0. + QtDeclarative
    By honza in forum Qt Programming
    Replies: 4
    Last Post: 8th November 2009, 14:49
  3. Zip module for Qt
    By arpspatel in forum Qt Programming
    Replies: 1
    Last Post: 28th October 2009, 06:34
  4. SVG module
    By mind_freak in forum Qt Programming
    Replies: 6
    Last Post: 21st August 2009, 05:01
  5. SQL-Module
    By phil_ in forum Newbie
    Replies: 7
    Last Post: 22nd January 2006, 16:24

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.