Hi; I'm working on getting Python (PySide) able to export Python types to QML the same way you can do with C++ types, i.e.:
class Foo(QObject): ... qmlRegisterType(Foo, "foo.bar.com", 1, 0, "FooOnQml_huhu") I took a look on QtDeclarative sources and faced some issues to integrate Python or any other language to QML. First, QML uses qmlRegisterType<T> function to register a type, this function just fills a struct with some info and pass it to the depths of QML, one of these fields is a function pointer, this function pointer is used as a factory function by QML to create instances of the exported type T. So what's the problem? Using a template function everything can be decided at compile time, so we have a different factory function for each type exported to QML, perfect for C++ but Qt bindings doesn't have the information about user created types at compile time, so we can't have a factory function for each type created by the user as we have on C++. One way to ease the work of people doing Qt bindings to support QML is adding a bit more info on this factory function, so we can use a Proxy object to decide what type need to be instantiated. I attached a pseudo-patch that implements this idea, pseudo because I wrote it just to show what changes are needed, if I get a thumbs up about it I can work, test and create a merge request for it. Any comments? Any chances to get it or something like it into the mainline for Qt4.7.1? -- Hugo Parente Lima INdT - Instituto Nokia de Tecnologia
From 90d3b18456eea4eb3c88366945cff62191c04331 Mon Sep 17 00:00:00 2001 From: Hugo Parente Lima <hugo...@gmail.com> Date: Mon, 25 Oct 2010 18:59:58 -0200 Subject: [PATCH] Makes possible to Qt bindings to export user types to QML. --- src/declarative/qml/qdeclarativemetatype.cpp | 2 +- src/declarative/qml/qdeclarativeprivate.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/declarative/qml/qdeclarativemetatype.cpp b/src/declarative/qml/qdeclarativemetatype.cpp index 7a78a1f..c16dd15 100644 --- a/src/declarative/qml/qdeclarativemetatype.cpp +++ b/src/declarative/qml/qdeclarativemetatype.cpp @@ -379,7 +379,7 @@ QObject *QDeclarativeType::create() const d->init(); QObject *rv = (QObject *)operator new(d->m_allocationSize); - d->m_newFunc(rv); + d->m_newFunc(rv, d->m_name, d->m_version_maj, d->m_version_min); if (rv && !d->m_metaObjects.isEmpty()) (void *)new QDeclarativeProxyMetaObject(rv, &d->m_metaObjects); diff --git a/src/declarative/qml/qdeclarativeprivate.h b/src/declarative/qml/qdeclarativeprivate.h index d45ddbc..2325638 100644 --- a/src/declarative/qml/qdeclarativeprivate.h +++ b/src/declarative/qml/qdeclarativeprivate.h @@ -91,7 +91,7 @@ namespace QDeclarativePrivate }; template<typename T> - void createInto(void *memory) { new (memory) QDeclarativeElement<T>; } + void createInto(void *memory, const QString&, int, int) { new (memory) QDeclarativeElement<T>; } template<typename T> QObject *createParent(QObject *p) { return new T(p); } @@ -197,7 +197,7 @@ namespace QDeclarativePrivate int typeId; int listId; int objectSize; - void (*create)(void *); + void (*create)(void *, const QString&, int, int); QString noCreationReason; const char *uri; -- 1.7.3.2
signature.asc
Description: This is a digitally signed message part.
_______________________________________________ Qt-qml mailing list Qt-qml@trolltech.com http://lists.trolltech.com/mailman/listinfo/qt-qml