PDA

View Full Version : [Qt 4.6] Add a plugin to the QtDeclarative module



zuck
19th April 2010, 17:21
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



class MYLIBSHARED_EXPORT MyClass : public QObject
{
Q_OBJECT

Q_PROPERTY(bool checkable READ isCheckable WRITE setCheckable NOTIFY checkableChanged)

// ...
};

QML_DECLARE_TYPE(MyClass)


myclass.cpp



#include "myclass.h"

// ...

QML_DEFINE_TYPE(MyLibrary, 1,0, MyClass, MyClass)


mylibrary.pro



QT += declarative
TEMPLATE = lib
DEFINES += MYLIBSHARED_LIBRARY
HEADERS += myclass.h
SOURCES += myclass.cpp


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

example.qml



import MyLibrary 1.0

MyClass {
}


How can i do this?

Thanks!

zuck
20th April 2010, 10:48
From the documentation:



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


import Qt 4.6

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?

zuck
21st April 2010, 11:48
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).