changeset 373:1f189d0ceab4

merge
author Max Samukha <maxter@spambox.com>
date Thu, 08 Jul 2010 17:20:02 +0300
parents a032df77b6ab (diff) 12f60887ed15 (current diff)
children 681af90e1d53
files cpp/qt_qtd/qtd_core.cpp d2/qt/core/QPoint.d generator/typesystem_gui.xml
diffstat 36 files changed, 1209 insertions(+), 663 deletions(-) [+]
line wrap: on
line diff
--- a/CMakeLists.txt	Wed Jul 07 22:54:12 2010 +0100
+++ b/CMakeLists.txt	Thu Jul 08 17:20:02 2010 +0300
@@ -496,30 +496,29 @@
     target_link_libraries(cpp_${package} ${link_cpp} )
     set(d_objs ${d_objs} ${objects})
 
-    if(CPP_SHARED AND CMAKE_HOST_WIN32)
-        ## Create an implib library which will be linked to the D part.
-        set(cpp_lib ${CMAKE_BINARY_DIR}/lib/libcpp_${package}.dll)
-        set(cpp_lib_native ${cpp_lib})
-        make_native_path(cpp_lib_native)
-        set(d_implib ${CMAKE_BINARY_DIR}/CMakeFiles/${package}.dir/cpp_${package}.lib)
-        set(d_implib_native ${d_implib})
-        make_native_path(d_implib_native)
-        add_custom_command(
-            OUTPUT "${d_implib}"
-            COMMAND "${IMPLIB}"
-            ARGS  /system /PAGESIZE:64 ${d_implib_native} ${cpp_lib_native}
-            DEPENDS  "cpp_${package}"
-            COMMENT "Creating implib ${lib_name}"
-            )
+    if(CPP_SHARED)
+        set(cpp_lib ${CMAKE_BINARY_DIR}/lib/libcpp_${package}.${CMAKE_SHARED_LIBRARY_SUFFIX})
         install(FILES ${cpp_lib} COMPONENT qtd DESTINATION lib)
+
+        if(CMAKE_HOST_WIN32)
+            ## Create an implib library which will be linked to the D part.
+            set(cpp_lib_native ${cpp_lib})
+            make_native_path(cpp_lib_native)
+            set(d_implib ${CMAKE_BINARY_DIR}/CMakeFiles/${package}.dir/cpp_${package}.lib)
+            set(d_implib_native ${d_implib})
+            make_native_path(d_implib_native)
+            add_custom_command(
+                OUTPUT "${d_implib}"
+                COMMAND "${IMPLIB}"
+                ARGS  /system /PAGESIZE:64 ${d_implib_native} ${cpp_lib_native}
+                DEPENDS  "cpp_${package}"
+                COMMENT "Creating implib ${lib_name}"
+                )
+        endif()
     else()
         set(${package}_lib_param Qt${package_big})
     endif()
-    #FIXME remove redundancy again. see above
-    if(CPP_SHARED AND CMAKE_HOST_UNIX)
-        set(cpp_lib ${CMAKE_BINARY_DIR}/lib/libcpp_${package}.so)
-        install(FILES ${cpp_lib} COMPONENT qtd DESTINATION lib)
-    endif()
+
     ## Link the D part.
     add_d_target(${lib_name} NOT_DETECT_DEPENDS TYPE ${build_type} INCLUDES ${QTD_IMPORT_PATH} SOURCES ${d_sources} OBJECTS ${cpp_objs} ${d_implib}
           OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib DEPENDS ${d_implib} )
--- a/build/core.txt	Wed Jul 07 22:54:12 2010 +0100
+++ b/build/core.txt	Thu Jul 08 17:20:02 2010 +0300
@@ -15,7 +15,8 @@
     qt_core/QString_shell
     qt_core/QVariant_shell
     qt_core/QModelIndex_shell
-    qt_core/QMetaObject_shell)
+    qt_core/QMetaObject_shell
+    )
 ## Module specific d files.
 set (d_qt_files
     QGlobal
@@ -23,11 +24,15 @@
     core/QMetaObject
     core/QTypeInfo
     core/QList
-    core/QLine core/QLineF
+    core/QLine
+    core/QLineF
     core/QModelIndex
-    core/QRect core/QRectF
-    core/QSize core/QSizeF
-    core/QPoint core/QPointF
+    core/QRect
+    core/QRectF
+    core/QSize
+    core/QSizeF
+    core/QPoint
+    core/QPointF
     core/QVariant
     )
 set (d_qtd_files
@@ -48,6 +53,23 @@
     meta/Compiletime
     meta/Runtime
     )
+
+# unittest files
+if(UNITTEST)
+    set (cpp_files ${cpp_files}
+        qt_core/test/Objects
+    )
+    set (d_qt_files ${d_qt_files}
+        core/test/Objects
+    )
+endif()
+
+if(${CMAKE_BUILD_TYPE} STREQUAL "Debug" OR UNITTEST)
+set (d_qtd_files ${d_qtd_files}
+        Debug
+    )
+endif()
+
 set (d_generated_files core/Qt QDefines)
 ## Classes.
 set (classes
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cpp/qt_core/test/Objects.cpp	Thu Jul 08 17:20:02 2010 +0300
@@ -0,0 +1,18 @@
+#include <QObject>
+#include <QEvent>
+
+extern "C" void* qtd_test_QObject_create(void* parent)
+{
+    return new QObject((QObject*)parent);
+}
+
+extern "C" void qtd_test_QObject_delete(void* nativeId)
+{
+    delete (QObject*)nativeId;
+}
+
+extern "C" void qtd_test_QObject_event(void* nativeId)
+{
+     QEvent event(QEvent::None);
+    ((QObject*)nativeId)->event(&event);
+}
\ No newline at end of file
--- a/cpp/qt_qtd/qtd_core.cpp	Wed Jul 07 22:54:12 2010 +0100
+++ b/cpp/qt_qtd/qtd_core.cpp	Thu Jul 08 17:20:02 2010 +0300
@@ -4,16 +4,24 @@
  */
 
 #include "qtd_core.h"
-#include <iostream>
+#include <typeinfo>
 
 QTD_EXPORT(CORE, toUtf8);
 QTD_EXPORT(CORE, QtdObject_delete);
 
-QTD_EXTERN QTD_DLL_EXPORT void qtd_initCore()
+QTD_EXTERN QTD_DLL_PUBLIC void qtdInitCore()
 {
     QObjectLink::userDataId = QObject::registerUserData();
 }
 
+QTD_EXTERN QTD_DLL_PUBLIC bool qtdTypeInfosEqual(void* info1, void* info2)
+{
+    std::type_info* i1 = (std::type_info*)info1;
+    std::type_info* i2 = (std::type_info*)info2;
+
+    return i1 == i2 || strcmp(i1->name(), i2->name()) == 0;
+}
+
 QTD_EXTERN QTD_DLL_PUBLIC QModelIndex qtd_to_QModelIndex(QModelIndexAccessor mia)
 {
     return * (QModelIndex *) (&mia) ;
@@ -47,13 +55,13 @@
 extern bool qUnregisterResourceData
     (int, const unsigned char *, const unsigned char *, const unsigned char *);
 
-QTD_EXTERN QTD_DLL_PUBLIC bool qtd_register_resource_data(int version, const unsigned char *tree,
+QTD_EXTERN QTD_DLL_PUBLIC bool qtd_qRegisterResourceData(int version, const unsigned char *tree,
                                          const unsigned char *name, const unsigned char *data)
 {
     return qRegisterResourceData(version, tree, name, data);
 }
 
-QTD_EXTERN QTD_DLL_PUBLIC bool qtd_unregister_resource_data(int version, const unsigned char *tree,
+QTD_EXTERN QTD_DLL_PUBLIC bool qtd_qUnregisterResourceData(int version, const unsigned char *tree,
                                            const unsigned char *name, const unsigned char *data)
 {
     return qUnregisterResourceData(version, tree, name, data);
--- a/d2/qt/core/QLine.d	Wed Jul 07 22:54:12 2010 +0100
+++ b/d2/qt/core/QLine.d	Thu Jul 08 17:20:02 2010 +0300
@@ -129,13 +129,13 @@
     }
 
     public final void writeTo(QDataStream arg__1) {
-        qtd_QLine_writeTo_QDataStream(&this, arg__1 is null ? null : arg__1.__nativeId);
+        qtd_QLine_writeTo_QDataStream(&this, arg__1 is null ? null : arg__1.qtdNativeId);
     }
 
     public final void readFrom(QDataStream arg__1) {
-        qtd_QLine_readFrom_QDataStream(&this, arg__1 is null ? null : arg__1.__nativeId);
+        qtd_QLine_readFrom_QDataStream(&this, arg__1 is null ? null : arg__1.qtdNativeId);
     }
-    
+
     // service stuff
     public alias void __isNativeValueType;
 
@@ -347,11 +347,11 @@
     }
 
     public final void writeTo(QDataStream arg__1) {
-        qtd_QLineF_writeTo_QDataStream(&this, arg__1 is null ? null : arg__1.__nativeId);
+        qtd_QLineF_writeTo_QDataStream(&this, arg__1 is null ? null : arg__1.qtdNativeId);
     }
 
     public final void readFrom(QDataStream arg__1) {
-        qtd_QLineF_readFrom_QDataStream(&this, arg__1 is null ? null : arg__1.__nativeId);
+        qtd_QLineF_readFrom_QDataStream(&this, arg__1 is null ? null : arg__1.qtdNativeId);
     }
 
     public final void setAngle(double angle) {
--- a/d2/qt/core/QList.d	Wed Jul 07 22:54:12 2010 +0100
+++ b/d2/qt/core/QList.d	Thu Jul 08 17:20:02 2010 +0300
@@ -345,7 +345,7 @@
                 else static if (isValueType!T)
                 {
                     void* ptr = cast(void*)(isLarge!T() || isStatic!T() ? v : &this);
-                    return new T(ptr, QtdObjectFlags.nativeOwnership);
+                    return new T(ptr, QtdObjectInitFlags.nativeOwnership);
                 }
                 else
                 {
@@ -482,14 +482,14 @@
             static if (isValueType!T)
                 {
                     if (isLarge!T() || isStatic!T()) // TODO should be static if
-                        n.v = T.__constructNativeCopy(t.__nativeId); // n.v = new T(t);
+                        n.v = T.__constructNativeCopy(t.qtdNativeId); // n.v = new T(t);
                     else if (isComplex!T())
-                        T.__constructPlacedNativeCopy(t.__nativeId, n); //  new (n) T(t);
+                        T.__constructPlacedNativeCopy(t.qtdNativeId, n); //  new (n) T(t);
                     else
-                        T.__constructPlacedNativeCopy(t.__nativeId, n); // TODO should be *cast(T*)(n) = cast(T)(t); as it is a primitive type. fix when they are implemented with structs
+                        T.__constructPlacedNativeCopy(t.qtdNativeId, n); // TODO should be *cast(T*)(n) = cast(T)(t); as it is a primitive type. fix when they are implemented with structs
                 }
             else // in case of QObject or Object Qt types we place a pointer to a native object in the node
-                n = cast(Node*) t.__nativeId;
+                n = cast(Node*) t.qtdNativeId;
         }
     else static if (is(T == string))
     {
@@ -543,7 +543,7 @@
         for(int i = 0; i < res.length; ++i)
         {
             static if (isValueType!T)
-                res[i] = new T(T.__constructNativeCopy(this.at(i).__nativeId)); // Node should probably provide a ptr method to directly extract pointer to the native value stored in the list to avoid creating a dummy D object in t()
+                res[i] = new T(T.__constructNativeCopy(this.at(i).qtdNativeId)); // Node should probably provide a ptr method to directly extract pointer to the native value stored in the list to avoid creating a dummy D object in t()
             else
                 res[i] = this.opIndex(i);
         }
--- a/d2/qt/core/QMetaObject.d	Wed Jul 07 22:54:12 2010 +0100
+++ b/d2/qt/core/QMetaObject.d	Thu Jul 08 17:20:02 2010 +0300
@@ -9,6 +9,7 @@
     qtd.Marshal,
     qtd.MOC,
     qtd.String,
+    qtd.Signal,
     std.typetuple,
     std.traits,
     std.c.stdlib;
@@ -85,32 +86,7 @@
     }
 }
 
-/**
-    Base class for QtD meta-classes.
- */
-abstract class QtdMetaClass : MetaClass
-{
-private:
-    void* nativeId_;
 
-public:
-
-    this() {}
-
-    /**
-     */
-    @property
-    void* nativeId()
-    {
-        return nativeId_;
-    }
-
-    void construct(T)()
-    {
-        super.construct!T();
-        nativeId_ = T.qtd_nativeStaticMetaObject();
-    }
-}
 
 struct QMetaObjectNative
 {
@@ -120,6 +96,20 @@
     void *extradata;
 }
 
+// COMPILER BUG: causes a forward reference error if placed inside QMetaObject
+enum MetaCall
+{
+    InvokeMetaMethod,
+    ReadProperty,
+    WriteProperty,
+    ResetProperty,
+    QueryPropertyDesignable,
+    QueryPropertyScriptable,
+    QueryPropertyStored,
+    QueryPropertyEditable,
+    QueryPropertyUser,
+    CreateInstance
+}
 
 /**
  */
@@ -127,24 +117,8 @@
 {
     alias typeof(this) This;
 
-    private QObject function(void* nativeId) _createWrapper;
-
     this() {}
 
-    enum Call
-    {
-        InvokeMetaMethod,
-        ReadProperty,
-        WriteProperty,
-        ResetProperty,
-        QueryPropertyDesignable,
-        QueryPropertyScriptable,
-        QueryPropertyStored,
-        QueryPropertyEditable,
-        QueryPropertyUser,
-        CreateInstance
-    }
-
     alias createImpl!This create;
 
     void construct(T : QObject)()
@@ -158,12 +132,6 @@
             else
                 alias T Concrete;
 
-            _createWrapper = function QObject(void* nativeId) {
-                    auto obj = new Concrete(nativeId, cast(QtdObjectFlags)(QtdObjectFlags.nativeOwnership | QtdObjectFlags.dynamicEntity));
-                    T.__createEntity(nativeId, cast(void*)obj);
-                    return obj;
-                };
-
             T._populateMetaInfo(this);
         }
         // create run time meta-objects for user-defined signals and slots
@@ -277,7 +245,7 @@
         return this;
     }
 
-    QObject getObject(void* nativeObjId)
+    override QObject getWrapper(void* nativeObjId, QtdObjectInitFlags initFlags = QtdObjectInitFlags.none)
     {
         QObject result;
 
@@ -289,7 +257,7 @@
                 auto moId = qtd_QObject_metaObject(nativeObjId);
                 auto nId = nativeId;
                 if (nId == moId)
-                     result = _createWrapper(nativeObjId);
+                     result = static_cast!QObject(_createWrapper(nativeObjId, initFlags));
                 else
                 {
                     // get native metaobjects for the entire derivation lattice
@@ -311,7 +279,8 @@
                     while (moCount > 0)
                         moIds[--moCount] = moId = qtd_QMetaObject_superClass(moId);
 
-                    result = lookUpDerived(moIds)._createWrapper(nativeObjId);
+                    auto mo = lookUpDerived(moIds);
+                    result = static_cast!QObject(mo._createWrapper(nativeObjId, initFlags));
                 }
             }
         }
@@ -321,19 +290,19 @@
 
     static void activate(QObject sender, QMetaObject m, int local_signal_index, void **argv)
     {
-        qtd_QMetaObject_activate_3(sender.__nativeId, m.nativeId, local_signal_index, argv);
+        qtd_QMetaObject_activate_3(sender.qtdNativeId, m.nativeId, local_signal_index, argv);
     }
 
     static void activate(QObject sender, QMetaObject m, int from_local_signal_index, int to_local_signal_index, void **argv)
     {
-        qtd_QMetaObject_activate_4(sender.__nativeId, m.nativeId, from_local_signal_index, to_local_signal_index, argv);
+        qtd_QMetaObject_activate_4(sender.qtdNativeId, m.nativeId, from_local_signal_index, to_local_signal_index, argv);
     }
 
     static bool connect(const QObject sender, int signal_index,
                         const QObject receiver, int method_index,
                         int type = 0, int *types = null)
     {
-        return qtd_QMetaObject_connect(sender.__nativeId, signal_index, receiver.__nativeId, method_index, type, types);
+        return qtd_QMetaObject_connect(sender.qtdNativeId, signal_index, receiver.qtdNativeId, method_index, type, types);
     }
 
     int indexOfMethod_Cpp(string method)
@@ -425,6 +394,7 @@
  */
 mixin template Q_CLASSINFO(string name, string value)
 {
+    import qtd.meta.Compiletime;
     mixin InnerAttribute!("Q_CLASSINFO", AttributeOptions.allowMultiple, name, value);
 }
 
@@ -435,44 +405,6 @@
     static assert(false, "not implemented");
 }
 
-version (QtdUnittest)
-{
-    // COMPILER BUG: cannot put this inside the unittest block as static class.
-    class QMetaObject_A : QObject
-    {
-        mixin Q_CLASSINFO!("author", "Sabrina Schweinsteiger");
-        mixin Q_CLASSINFO!("url", "http://doc.moosesoft.co.uk/1.0/");
-
-        static int slot1Called;
-
-        final
-        {
-            void signal_signal1();
-            void signal_signal2(int);
-        }
-
-
-        void slot_slot1()
-        {
-            slot1Called++;
-        }
-
-        mixin Q_OBJECT;
-    }
-
-    unittest
-    {
-        scope a = new QMetaObject_A;
-        QObject.connect(a, "signal1", a, "slot1");
-        a.signal1();
-        assert(QMetaObject_A.slot1Called == 1);
-
-        QObject.connect(a, "signal2", a, "slot1");
-        a.signal2(42);
-        assert(QMetaObject_A.slot1Called == 2);
-    }
- }
-
 extern(C) void qtd_QMetaObject_activate_3(void* sender, void* m, int local_signal_index, void **argv);
 extern(C) void qtd_QMetaObject_activate_4(void *sender, void* m, int from_local_signal_index, int to_local_signal_index, void **argv);
 extern(C) bool qtd_QMetaObject_connect(const void* sender, int signal_index,
--- a/d2/qt/core/QMetaType.d	Wed Jul 07 22:54:12 2010 +0100
+++ b/d2/qt/core/QMetaType.d	Thu Jul 08 17:20:02 2010 +0300
@@ -60,7 +60,7 @@
     if (!name.length)
 	name = typeid(T).toString;
 
-    return qtd_registerType(toStringz(name), &MetaTypeOps!(T).ctor, &MetaTypeOps!(T).dtor);
+    return qtd_qRegisterMetaType(toStringz(name), &MetaTypeOps!(T).ctor, &MetaTypeOps!(T).dtor);
 }
 
 /* Not work....
@@ -101,6 +101,3 @@
     qtd_registerStreamOperators(toStringz(name), cast(StreamOp)&saveOpC, cast(StreamOp)&loadOpC);
 }
 */
-private extern(C) void qtd_registerStreamOperators(char *typeName, StreamOp saveOp, StreamOp loadOp);
-private extern(C) int qtd_registerType(in char* namePtr, Ctor ctor, Dtor dtor);
-extern(C) int qtd_MetatypeId(in char *id); // TODO: wrap to D.
\ No newline at end of file
--- a/d2/qt/core/QPoint.d	Wed Jul 07 22:54:12 2010 +0100
+++ b/d2/qt/core/QPoint.d	Thu Jul 08 17:20:02 2010 +0300
@@ -86,13 +86,13 @@
     }
 
     public final void writeTo(QDataStream arg__1) {
-        qtd_QPoint_writeTo_QDataStream(&this, arg__1 is null ? null : arg__1.__nativeId);
+        qtd_QPoint_writeTo_QDataStream(&this, arg__1 is null ? null : arg__1.qtdNativeId);
     }
 
     public final void readFrom(QDataStream arg__1) {
-        qtd_QPoint_readFrom_QDataStream(&this, arg__1 is null ? null : arg__1.__nativeId);
+        qtd_QPoint_readFrom_QDataStream(&this, arg__1 is null ? null : arg__1.qtdNativeId);
     }
-    
+
     // service stuff
     public alias void __isNativeValueType;
 
@@ -214,11 +214,11 @@
     }
 
     public final void writeTo(QDataStream arg__1) {
-        qtd_QPointF_writeTo_QDataStream(&this, arg__1 is null ? null : arg__1.__nativeId);
+        qtd_QPointF_writeTo_QDataStream(&this, arg__1 is null ? null : arg__1.qtdNativeId);
     }
 
     public final void readFrom(QDataStream arg__1) {
-        qtd_QPointF_readFrom_QDataStream(&this, arg__1 is null ? null : arg__1.__nativeId);
+        qtd_QPointF_readFrom_QDataStream(&this, arg__1 is null ? null : arg__1.qtdNativeId);
     }
 
     // service stuff
--- a/d2/qt/core/QRect.d	Wed Jul 07 22:54:12 2010 +0100
+++ b/d2/qt/core/QRect.d	Thu Jul 08 17:20:02 2010 +0300
@@ -306,11 +306,11 @@
     }
 
     public final void writeTo(QDataStream arg__1) {
-        qtd_QRect_writeTo_QDataStream(&this, arg__1 is null ? null : arg__1.__nativeId);
+        qtd_QRect_writeTo_QDataStream(&this, arg__1 is null ? null : arg__1.qtdNativeId);
     }
 
     public final void readFrom(QDataStream arg__1) {
-        qtd_QRect_readFrom_QDataStream(&this, arg__1 is null ? null : arg__1.__nativeId);
+        qtd_QRect_readFrom_QDataStream(&this, arg__1 is null ? null : arg__1.qtdNativeId);
     }
 
     public final QRect opAnd(const QRect r) const {
@@ -385,4 +385,4 @@
 private extern(C) QRect  qtd_QRect_operator_and_QRect(const void* __this_nativeId,
  const void* r0);
 private extern(C) QRect  qtd_QRect_operator_or_QRect(const void* __this_nativeId,
- const void* r0);
\ No newline at end of file
+ const void* r0);
--- a/d2/qt/core/QRectF.d	Wed Jul 07 22:54:12 2010 +0100
+++ b/d2/qt/core/QRectF.d	Thu Jul 08 17:20:02 2010 +0300
@@ -286,11 +286,11 @@
     }
 
     public final void writeTo(QDataStream arg__1) {
-        qtd_QRectF_writeTo_QDataStream(&this, arg__1 is null ? null : arg__1.__nativeId);
+        qtd_QRectF_writeTo_QDataStream(&this, arg__1 is null ? null : arg__1.qtdNativeId);
     }
 
     public final void readFrom(QDataStream arg__1) {
-        qtd_QRectF_readFrom_QDataStream(&this, arg__1 is null ? null : arg__1.__nativeId);
+        qtd_QRectF_readFrom_QDataStream(&this, arg__1 is null ? null : arg__1.qtdNativeId);
     }
 
     public final QRectF opOr(ref QRectF r) const {
@@ -301,7 +301,7 @@
     {
         return qtd_QRectF_toAlignedRect(cast(void*)&this);
     }
-    
+
     // service stuff
     public alias void __isNativeValueType;
 
@@ -337,4 +337,4 @@
  void* arg__1);
 private extern(C) QRectF  qtd_QRectF_operator_or_QRectF(void* __this_nativeId,
  void* r0);
-private extern(C) QRect  qtd_QRectF_toAlignedRect(void* __this_nativeId);
\ No newline at end of file
+private extern(C) QRect  qtd_QRectF_toAlignedRect(void* __this_nativeId);
--- a/d2/qt/core/QVariant.d	Wed Jul 07 22:54:12 2010 +0100
+++ b/d2/qt/core/QVariant.d	Thu Jul 08 17:20:02 2010 +0300
@@ -139,133 +139,133 @@
 
     public this() {
         void* __qt_return_value = qtd_QVariant_QVariant();
-        super(__qt_return_value);
+        super(__qt_return_value, QtdObjectInitFlags.createdByD);
     }
 
 
     public this(QDataStream s) {
-        void* __qt_return_value = qtd_QVariant_QVariant_QDataStream(s is null ? null : s.__nativeId);
-        super(__qt_return_value);
+        void* __qt_return_value = qtd_QVariant_QVariant_QDataStream(s is null ? null : s.qtdNativeId);
+        super(__qt_return_value, QtdObjectInitFlags.createdByD);
     }
 
 
     public this(Qt.GlobalColor color) {
         void* __qt_return_value = qtd_QVariant_QVariant_GlobalColor(color);
-        super(__qt_return_value);
+        super(__qt_return_value, QtdObjectInitFlags.createdByD);
     }
 
 
     public this(bool b) {
         void* __qt_return_value = qtd_QVariant_QVariant_bool(b);
-        super(__qt_return_value);
+        super(__qt_return_value, QtdObjectInitFlags.createdByD);
     }
 
 
     public this(QBitArray bitarray) {
-        void* __qt_return_value = qtd_QVariant_QVariant_QBitArray(bitarray is null ? null : bitarray.__nativeId);
-        super(__qt_return_value);
+        void* __qt_return_value = qtd_QVariant_QVariant_QBitArray(bitarray is null ? null : bitarray.qtdNativeId);
+        super(__qt_return_value, QtdObjectInitFlags.createdByD);
     }
 
 
     public this(QByteArray bytearray) {
-        void* __qt_return_value = qtd_QVariant_QVariant_QByteArray(bytearray is null ? null : bytearray.__nativeId);
-        super(__qt_return_value);
+        void* __qt_return_value = qtd_QVariant_QVariant_QByteArray(bytearray is null ? null : bytearray.qtdNativeId);
+        super(__qt_return_value, QtdObjectInitFlags.createdByD);
     }
 
 
     public this(QDate date) {
-        void* __qt_return_value = qtd_QVariant_QVariant_QDate(date is null ? null : date.__nativeId);
-        super(__qt_return_value);
+        void* __qt_return_value = qtd_QVariant_QVariant_QDate(date is null ? null : date.qtdNativeId);
+        super(__qt_return_value, QtdObjectInitFlags.createdByD);
     }
 
 
     public this(QDateTime datetime) {
-        void* __qt_return_value = qtd_QVariant_QVariant_QDateTime(datetime is null ? null : datetime.__nativeId);
-        super(__qt_return_value);
+        void* __qt_return_value = qtd_QVariant_QVariant_QDateTime(datetime is null ? null : datetime.qtdNativeId);
+        super(__qt_return_value, QtdObjectInitFlags.createdByD);
     }
 
 
     public this(string str) {
         void* __qt_return_value = qtd_QVariant_QVariant_String(str);
-        super(__qt_return_value);
+        super(__qt_return_value, QtdObjectInitFlags.createdByD);
     }
 
 
     public this(QLine line) {
         void* __qt_return_value = qtd_QVariant_QVariant_QLine(&line);
-        super(__qt_return_value);
+        super(__qt_return_value, QtdObjectInitFlags.createdByD);
     }
 
 
     public this(QLineF line) {
         void* __qt_return_value = qtd_QVariant_QVariant_QLineF(&line);
-        super(__qt_return_value);
+        super(__qt_return_value, QtdObjectInitFlags.createdByD);
     }
 
 
     public this(QLocale locale) {
-        void* __qt_return_value = qtd_QVariant_QVariant_QLocale(locale is null ? null : locale.__nativeId);
-        super(__qt_return_value);
+        void* __qt_return_value = qtd_QVariant_QVariant_QLocale(locale is null ? null : locale.qtdNativeId);
+        super(__qt_return_value, QtdObjectInitFlags.createdByD);
     }
 
 
     public this(QPoint pt) {
         void* __qt_return_value = qtd_QVariant_QVariant_QPoint(&pt);
-        super(__qt_return_value);
+        super(__qt_return_value, QtdObjectInitFlags.createdByD);
     }
 
 
     public this(QPointF pt) {
         void* __qt_return_value = qtd_QVariant_QVariant_QPointF(&pt);
-        super(__qt_return_value);
+        super(__qt_return_value, QtdObjectInitFlags.createdByD);
     }
 
 
     public this(QRect rect) {
         void* __qt_return_value = qtd_QVariant_QVariant_QRect(&rect);
-        super(__qt_return_value);
+        super(__qt_return_value, QtdObjectInitFlags.createdByD);
     }
 
 
     public this(QRectF rect) {
         void* __qt_return_value = qtd_QVariant_QVariant_QRectF(&rect);
-        super(__qt_return_value);
+        super(__qt_return_value, QtdObjectInitFlags.createdByD);
     }
 
 
     public this(QRegExp regExp) {
-        void* __qt_return_value = qtd_QVariant_QVariant_QRegExp(regExp is null ? null : regExp.__nativeId);
-        super(__qt_return_value);
+        void* __qt_return_value = qtd_QVariant_QVariant_QRegExp(regExp is null ? null : regExp.qtdNativeId);
+        super(__qt_return_value, QtdObjectInitFlags.createdByD);
     }
 
 
     public this(QSize size) {
         void* __qt_return_value = qtd_QVariant_QVariant_QSize(&size);
-        super(__qt_return_value);
+        super(__qt_return_value, QtdObjectInitFlags.createdByD);
     }
 
 
     public this(QSizeF size) {
         void* __qt_return_value = qtd_QVariant_QVariant_QSizeF(&size);
-        super(__qt_return_value);
+        super(__qt_return_value, QtdObjectInitFlags.createdByD);
     }
 
 
     public this(QTime time) {
-        void* __qt_return_value = qtd_QVariant_QVariant_QTime(time is null ? null : time.__nativeId);
-        super(__qt_return_value);
+        void* __qt_return_value = qtd_QVariant_QVariant_QTime(time is null ? null : time.qtdNativeId);
+        super(__qt_return_value, QtdObjectInitFlags.createdByD);
     }
 
 
     public this(QUrl url) {
-        void* __qt_return_value = qtd_QVariant_QVariant_QUrl(url is null ? null : url.__nativeId);
-        super(__qt_return_value);
+        void* __qt_return_value = qtd_QVariant_QVariant_QUrl(url is null ? null : url.qtdNativeId);
+        super(__qt_return_value, QtdObjectInitFlags.createdByD);
     }
 
 
     public this(QVariant other) {
-        void* __qt_return_value = qtd_QVariant_QVariant_QVariant(other is null ? null : other.__nativeId);
-        super(__qt_return_value);
+        void* __qt_return_value = qtd_QVariant_QVariant_QVariant(other is null ? null : other.qtdNativeId);
+        super(__qt_return_value, QtdObjectInitFlags.createdByD);
     }
 
 /*
@@ -277,37 +277,37 @@
 
     public this(double d) {
         void* __qt_return_value = qtd_QVariant_QVariant_double(d);
-        super(__qt_return_value);
+        super(__qt_return_value, QtdObjectInitFlags.createdByD);
     }
 
 
     public this(int i) {
         void* __qt_return_value = qtd_QVariant_QVariant_int(i);
-        super(__qt_return_value);
+        super(__qt_return_value, QtdObjectInitFlags.createdByD);
     }
 
 
     public this(int typeOrUserType, void* copy) {
         void* __qt_return_value = qtd_QVariant_QVariant_int_nativepointervoid(typeOrUserType, copy);
-        super(__qt_return_value);
+        super(__qt_return_value, QtdObjectInitFlags.createdByD);
     }
 
 
     public this(long ll) {
         void* __qt_return_value = qtd_QVariant_QVariant_long(ll);
-        super(__qt_return_value);
+        super(__qt_return_value, QtdObjectInitFlags.createdByD);
     }
 
 
     public this(uint ui) {
         void* __qt_return_value = qtd_QVariant_QVariant_uint(ui);
-        super(__qt_return_value);
+        super(__qt_return_value, QtdObjectInitFlags.createdByD);
     }
 
 
     public this(ulong ull) {
         void* __qt_return_value = qtd_QVariant_QVariant_ulong(ull);
-        super(__qt_return_value);
+        super(__qt_return_value, QtdObjectInitFlags.createdByD);
     }
 
     // TODO: No need for run time name. Reimplement.
@@ -315,7 +315,7 @@
     {
         int i = QMetaType.type(toStringz(name));
         assert(i > 0);
-        return qtd_QVariant_canConvert(__nativeId, i);
+        return qtd_QVariant_canConvert(qtdNativeId, i);
     }
 
     // TODO: reimplement
@@ -370,20 +370,20 @@
         {
             static if( is( Type == class ) || is( Type == interface ) )
             {
-                Object object = cast(Object)qtd_QVariant_data(__nativeId);
+                Object object = cast(Object)qtd_QVariant_data(qtdNativeId);
                 if(object)
                     return cast(Type)(object) !is null;
                 return false;
             }
             else static if (isDynamicArrayType!(Type) || isStaticArrayType!(Type) )
             {
-                auto array = cast(DArrayToC*)qtd_QVariant_data(__nativeId);
+                auto array = cast(DArrayToC*)qtd_QVariant_data(qtdNativeId);
                 return cast(Type)(array.array) !is null;
             }
             else
             {
                 int i = QMetaType.type(toStringz(typeid(Type).toString));
-                return qtd_QVariant_canConvert(__nativeId, i);
+                return qtd_QVariant_canConvert(qtdNativeId, i);
             }
         }
     }
@@ -437,188 +437,188 @@
 	    return toUrl;
 	else static if( is( Type == class ) || is( Type == interface ) )
 	{
-	    Object object = cast(Object)qtd_QVariant_data(__nativeId);
+	    Object object = cast(Object)qtd_QVariant_data(qtdNativeId);
 	    if(object)
 		return cast(Type)(object);
 	    return null;
 	}
 	else static if (isDynamicArrayType!(Type) || isStaticArrayType!(Type) )
 	{
-	    auto array = cast(DArrayToC*)qtd_QVariant_data(__nativeId);
+	    auto array = cast(DArrayToC*)qtd_QVariant_data(qtdNativeId);
 	    return cast(Type)(array.array);
 	}
 	else
 	{
-	    return *cast(Type*)qtd_QVariant_data(__nativeId);
+	    return *cast(Type*)qtd_QVariant_data(qtdNativeId);
 	}
     }
 
     public final void clear() {
-        qtd_QVariant_clear(__nativeId);
+        qtd_QVariant_clear(qtdNativeId);
     }
 
     protected final bool cmp(QVariant other) {
-        return qtd_QVariant_cmp_QVariant(__nativeId, other is null ? null : other.__nativeId);
+        return qtd_QVariant_cmp_QVariant(qtdNativeId, other is null ? null : other.qtdNativeId);
     }
 
     protected final void create(int type, void* copy) {
-        qtd_QVariant_create_int_nativepointervoid(__nativeId, type, copy);
+        qtd_QVariant_create_int_nativepointervoid(qtdNativeId, type, copy);
     }
 
     public final bool isNull() {
-        return qtd_QVariant_isNull(__nativeId);
+        return qtd_QVariant_isNull(qtdNativeId);
     }
 
     public final bool isValid() {
-        return qtd_QVariant_isValid(__nativeId);
+        return qtd_QVariant_isValid(qtdNativeId);
     }
 
     public final void load(QDataStream ds) {
-        qtd_QVariant_load_QDataStream(__nativeId, ds is null ? null : ds.__nativeId);
+        qtd_QVariant_load_QDataStream(qtdNativeId, ds is null ? null : ds.qtdNativeId);
     }
 
     public final void writeTo(QDataStream s) {
-        qtd_QVariant_writeTo_QDataStream(__nativeId, s is null ? null : s.__nativeId);
+        qtd_QVariant_writeTo_QDataStream(qtdNativeId, s is null ? null : s.qtdNativeId);
     }
 
     public final QVariant operator_assign(QVariant other) {
-        void* __qt_return_value = qtd_QVariant_operator_assign_QVariant(__nativeId, other is null ? null : other.__nativeId);
-        return new QVariant(__qt_return_value, QtdObjectFlags.nativeOwnership);
+        void* __qt_return_value = qtd_QVariant_operator_assign_QVariant(qtdNativeId, other is null ? null : other.qtdNativeId);
+        return new QVariant(__qt_return_value, QtdObjectInitFlags.nativeOwnership);
     }
 
     private final bool operator_equal(QVariant v) {
-        return qtd_QVariant_operator_equal_QVariant(__nativeId, v is null ? null : v.__nativeId);
+        return qtd_QVariant_operator_equal_QVariant(qtdNativeId, v is null ? null : v.qtdNativeId);
     }
 
     public final void readFrom(QDataStream s) {
-        qtd_QVariant_readFrom_QDataStream(__nativeId, s is null ? null : s.__nativeId);
+        qtd_QVariant_readFrom_QDataStream(qtdNativeId, s is null ? null : s.qtdNativeId);
     }
 
     public final void save(QDataStream ds) {
-        qtd_QVariant_save_QDataStream(__nativeId, ds is null ? null : ds.__nativeId);
+        qtd_QVariant_save_QDataStream(qtdNativeId, ds is null ? null : ds.qtdNativeId);
     }
 
     public final QBitArray toBitArray() {
-        void* __qt_return_value = qtd_QVariant_toBitArray(__nativeId);
+        void* __qt_return_value = qtd_QVariant_toBitArray(qtdNativeId);
         return new QBitArray(__qt_return_value);
     }
 
     public final bool toBool() {
-        return qtd_QVariant_toBool(__nativeId);
+        return qtd_QVariant_toBool(qtdNativeId);
     }
 
     public final QByteArray toByteArray() {
-        void* __qt_return_value = qtd_QVariant_toByteArray(__nativeId);
+        void* __qt_return_value = qtd_QVariant_toByteArray(qtdNativeId);
         return new QByteArray(__qt_return_value);
     }
 
     public final QDate toDate() {
-        void* __qt_return_value = qtd_QVariant_toDate(__nativeId);
+        void* __qt_return_value = qtd_QVariant_toDate(qtdNativeId);
         return new QDate(__qt_return_value);
     }
 
     public final QDateTime toDateTime() {
-        void* __qt_return_value = qtd_QVariant_toDateTime(__nativeId);
+        void* __qt_return_value = qtd_QVariant_toDateTime(qtdNativeId);
         return new QDateTime(__qt_return_value);
     }
 
     public final double toDouble(bool* ok = null) {
-        return qtd_QVariant_toDouble_nativepointerbool(__nativeId, ok);
+        return qtd_QVariant_toDouble_nativepointerbool(qtdNativeId, ok);
     }
 
     public final int toInt(bool* ok = null) {
-        return qtd_QVariant_toInt_nativepointerbool(__nativeId, ok);
+        return qtd_QVariant_toInt_nativepointerbool(qtdNativeId, ok);
     }
 
     public final QLine toLine() {
-        return qtd_QVariant_toLine(__nativeId);
+        return qtd_QVariant_toLine(qtdNativeId);
     }
 
     public final QLineF toLineF() {
-        return qtd_QVariant_toLineF(__nativeId);
+        return qtd_QVariant_toLineF(qtdNativeId);
     }
 
     public final QLocale toLocale() {
-        void* __qt_return_value = qtd_QVariant_toLocale(__nativeId);
+        void* __qt_return_value = qtd_QVariant_toLocale(qtdNativeId);
         return new QLocale(__qt_return_value);
     }
 
     public final long toLongLong(bool* ok = null) {
-        return qtd_QVariant_toLongLong_nativepointerbool(__nativeId, ok);
+        return qtd_QVariant_toLongLong_nativepointerbool(qtdNativeId, ok);
     }
 
     public final QPoint toPoint() {
-        return qtd_QVariant_toPoint(__nativeId);
+        return qtd_QVariant_toPoint(qtdNativeId);
     }
 
     public final QPointF toPointF() {
-        return qtd_QVariant_toPointF(__nativeId);
+        return qtd_QVariant_toPointF(qtdNativeId);
     }
 
     public final QRect toRect() {
-        return qtd_QVariant_toRect(__nativeId);
+        return qtd_QVariant_toRect(qtdNativeId);
     }
 
     public final QRectF toRectF() {
-        return qtd_QVariant_toRectF(__nativeId);
+        return qtd_QVariant_toRectF(qtdNativeId);
     }
 
     public final QRegExp toRegExp() {
-        void* __qt_return_value = qtd_QVariant_toRegExp(__nativeId);
+        void* __qt_return_value = qtd_QVariant_toRegExp(qtdNativeId);
         return new QRegExp(__qt_return_value);
     }
 
     public final QSize toSize() {
-        return qtd_QVariant_toSize(__nativeId);
+        return qtd_QVariant_toSize(qtdNativeId);
     }
 
     public final QSizeF toSizeF() {
-        return qtd_QVariant_toSizeF(__nativeId);
+        return qtd_QVariant_toSizeF(qtdNativeId);
     }
 
     public final string toString() {
         string res;
-        qtd_QVariant_toString(__nativeId, &res);
+        qtd_QVariant_toString(qtdNativeId, &res);
         return res;
     }
 
     public final QTime toTime() {
-        void* __qt_return_value = qtd_QVariant_toTime(__nativeId);
+        void* __qt_return_value = qtd_QVariant_toTime(qtdNativeId);
         return new QTime(__qt_return_value);
     }
 
     public final uint toUInt(bool* ok = null) {
-        return qtd_QVariant_toUInt_nativepointerbool(__nativeId, ok);
+        return qtd_QVariant_toUInt_nativepointerbool(qtdNativeId, ok);
     }
 
     public final ulong toULongLong(bool* ok = null) {
-        return qtd_QVariant_toULongLong_nativepointerbool(__nativeId, ok);
+        return qtd_QVariant_toULongLong_nativepointerbool(qtdNativeId, ok);
     }
 
     public final QUrl toUrl() {
-        void* __qt_return_value = qtd_QVariant_toUrl(__nativeId);
+        void* __qt_return_value = qtd_QVariant_toUrl(qtdNativeId);
         return new QUrl(__qt_return_value);
     }
 
     public final char* typeName() {
-        return qtd_QVariant_typeName(__nativeId);
+        return qtd_QVariant_typeName(qtdNativeId);
     }
 
     public final Type type() {
-        return cast(Type)qtd_QVariant_type(__nativeId);
+        return cast(Type)qtd_QVariant_type(qtdNativeId);
     }
 
     public final int userType() {
-        return qtd_QVariant_userType(__nativeId);
+        return qtd_QVariant_userType(qtdNativeId);
     }
 // Field accessors
 
-    public this(void* native_id, QtdObjectFlags flags = QtdObjectFlags.none) {
-        super(native_id, flags);
+    public this(void* native_id, QtdObjectInitFlags initFlags = QtdObjectInitFlags.none) {
+        super(native_id, initFlags);
     }
 
-    protected override void __deleteNative() {
-        qtd_QVariant_destructor(__nativeId);
+    protected override void qtdDeleteNative() {
+        qtd_QVariant_destructor(qtdNativeId);
     }
 
     public alias void __isValueType;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/d2/qt/core/test/Objects.d	Thu Jul 08 17:20:02 2010 +0300
@@ -0,0 +1,141 @@
+module qt.core.test.QObject;
+
+// make sure QtdUnittest is defined
+version (QtdUnittest) {} else { static assert(false); }
+
+import
+    core.memory,
+    qtd.Debug,
+    qtd.meta.Runtime,
+    qt.core.QObject,
+    qt.core.QMetaObject;
+    
+import std.stdio;
+
+extern (C) void* qtd_test_QObject_create(void* parent);
+extern (C) void qtd_test_QObject_delete(void* nativeId);
+extern (C) void qtd_test_QObject_event(void* nativeId);
+
+class C1 : QObject
+{
+    mixin Q_CLASSINFO!("author", "Sabrina Schweinsteiger");
+    mixin Q_CLASSINFO!("url", "http://doc.moosesoft.co.uk/1.0/");
+
+    static int slot1Called;
+    static ClassInfo eventReceived;
+
+    this(QObject parent = null)
+    {
+        super(parent);
+    }
+
+    final
+    {
+        void signal_signal1();
+        void signal_signal2(int);
+    }
+
+    override bool event(QEvent event)
+    {
+        eventReceived = event.classinfo;
+        return false;
+    }
+
+    void slot_slot1()
+    {
+        slot1Called++;
+    }
+
+    static void reset()
+    {
+        slot1Called = 0;
+        eventReceived = null;
+    }
+
+    mixin Q_OBJECT;
+}
+
+void test1()
+{
+    auto c1 = new C1;
+}
+
+void test2()
+{
+    scope c1 = new C1;
+}
+
+void test3()
+{
+    auto ptr = qtd_test_QObject_create(null);
+    scope obj = meta!(QObject).getWrapper(ptr);
+    assert (qtdDebug.wrapperCount == 1);
+}
+
+void test4()
+{
+    scope c1 = new C1;
+    qtd_test_QObject_event(c1.qtdNativeId);
+    assert (c1.eventReceived !is null);
+    assert (c1.eventReceived.classinfo == QEvent.classinfo);
+}
+
+void test5()
+{
+    scope c1 = new C1;
+
+    QObject.connect(c1, "signal1", c1, "slot1");
+    c1.signal1();
+    assert(c1.slot1Called == 1);
+
+    QObject.connect(c1, "signal2", c1, "slot1");
+    c1.signal2(42);
+    assert(C1.slot1Called == 2);
+}
+
+unittest
+{
+    static void reset()
+    {
+        qtdDebug.reset();
+        C1.reset();
+    }
+
+    qtdDebug.info("Running unittests (" ~ __FILE__ ~")");
+
+
+    //test1
+    reset();
+    test1();
+    GC.collect();
+    
+    writeln("Collected");
+    assert(qtdDebug.wrapperCount == 1);
+    
+    
+    //test2
+    reset();
+    test2();
+    assert(qtdDebug.wrapperCount == 0);
+    assert(qtdDebug.nativeDeletedCount == 1);
+
+    //test3
+    reset();
+    test3();
+    assert(qtdDebug.wrapperCount == 0);
+    assert(qtdDebug.nativeDeletedCount == 1);
+    
+    //test4
+    reset();
+    test4();
+    GC.collect();
+    assert(qtdDebug.wrapperCount == 0);
+    assert(qtdDebug.nativeDeletedCount == 1);
+
+    //test5
+    qtdDebug.reset();
+    test5();
+    assert(qtdDebug.wrapperCount == 0);
+
+    qtdDebug.info("Unittests completed (" ~ __FILE__ ~")");
+}
--- a/d2/qtd/Core.d	Wed Jul 07 22:54:12 2010 +0100
+++ b/d2/qtd/Core.d	Thu Jul 08 17:20:02 2010 +0300
@@ -2,24 +2,47 @@
 
 import
     qtd.ctfe.Format,
-    std.stdio;
+    std.traits;
 
+/**
+    Casts T to U, bypassing dynamic cast checks
+ */
 T static_cast(T, U)(U obj)
 {
     return cast(T)cast(void*)obj;
 }
 
+/**
+    Strips qualifiers off the argument.
+ */
+auto ref unqual(T)(auto ref T v)
+{
+    static if (__traits(isRef, v))
+    {
+        auto p = cast(Unqual!(T)*)&v;
+        return *p;
+    }
+    else
+        return cast(Unqual!T)v;
+}
+
+/**
+    Just an alias to the type T. Useful for declarations
+    with anonymous types.
+ */
+template Type(T)
+{
+    alias T Type;
+}
+
 enum qtdExtern = "extern (C)";
 
 extern(C) alias void function() VoidFunc;
-extern(C) void qtd_initCore();
-
-immutable Object qtdMoLock;
+extern(C) void qtdInitCore();
 
 static this()
 {
-    qtdMoLock = cast(immutable)new Object;
-    qtd_initCore();
+    qtdInitCore();
 }
 
 /**
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/d2/qtd/Debug.d	Thu Jul 08 17:20:02 2010 +0300
@@ -0,0 +1,152 @@
+module qtd.Debug;
+
+version (QtdUnittest)
+    debug = UseQtdDebug;
+else debug (QtdDebug)
+    debug = UseQtdDebug;
+    
+debug (UseQtdDebug)
+{
+    import
+        std.string,
+        qtd.QtdObject;
+}
+
+string debugHandler(string handler, string[] args...)
+{
+    debug (UseQtdDebug)
+    {
+        string result = "qtdDebug." ~ handler ~ "(";
+        foreach (i, arg; args)
+        {
+            if (i)
+                result ~= ", ";
+            result ~= arg;
+        }
+        return result ~ ");";
+    }
+    else
+        return "";
+}
+
+debug (UseQtdDebug)
+{
+    debug (QtdVerbose)
+    {
+        import
+            std.stdio,
+            std.string;
+    }
+
+    final shared class QtdDebug
+    {
+        enum MessageType
+        {
+            info,
+            warning,
+            error
+        }
+
+        private
+        {
+            static immutable msgTypeStrs = ["Info", "Warning", "Error"];
+            int wrapperCount_;
+            int nativeDeletedCount_;
+
+            this() {}
+        }
+        
+        string wrapperToString(QtdObject wrapper)
+        {
+            static assert (QtdObjectFlags.sizeof == ubyte.sizeof);
+            auto flags = wrapper.qtdFlags;
+            return format("%s (nativeId: %s, this ptr: %s, flags: %b)", this, wrapper.qtdNativeId
+                , cast(void*)this, *cast(ubyte*)&flags);
+        }
+
+        void onWrapperConstructed(QtdObject wrapper)
+        {
+            info("QtdObject constructed: " ~ wrapperToString(wrapper));
+            wrapperCount_++;
+        }
+
+        void onWrapperDestruction(QtdObject wrapper)
+        {
+            info("Entering QtdObject destructor: " ~ wrapperToString(wrapper));
+        }
+
+        void onWrapperDestroyed(QtdObject wrapper)
+        {
+            info("Leaving QtdObject destructor: " ~ wrapperToString(wrapper));
+            wrapperCount_--;
+        }
+
+        void onNativeDeleted(QtdObject wrapper)
+        {
+            info("Native object deleted: " ~ wrapperToString(wrapper));
+            nativeDeletedCount_++;
+        }
+
+        void onWrapperOwnershipChanged(QtdObject wrapper)
+        {
+            info("Wrapper ownership chaged: " ~ wrapperToString(wrapper));
+        }
+
+        void onDeletingWrapperFromNative(void* dId)
+        {
+            info(format("Wrapper deletion initiated from C++ (wrapper id: %s)", dId));
+        }
+
+        @property int wrapperCount()
+        {
+            return wrapperCount_;
+        }
+
+        @property int nativeDeletedCount()
+        {
+            return nativeDeletedCount_;
+        }
+
+        void reset()
+        {
+            wrapperCount_ = 0;
+            nativeDeletedCount_ = 0;
+        }
+
+        static void info(lazy string msg)
+        {
+            message(msg, MessageType.info);
+        }
+
+        static void warning(lazy string msg)
+        {
+            message(msg, MessageType.warning);
+        }
+
+        static void error(lazy string msg)
+        {
+            message(msg, MessageType.error);
+        }
+
+        static void message(lazy string msg, MessageType msgType = MessageType.info)
+        {
+            // The check is deliberately placed here and not at the call sites.
+            // For simplicity, there are only two levels of debug verbosity:
+            // verbose and silent.
+            debug (QtdVerbose)
+                writefln("[QtD %s] %s",  msgTypeStrs[msgType], msg);
+        }
+    }
+
+    private shared QtdDebug _qtdDebug;
+    static QtdDebug qtdDebug()
+    {
+        return _qtdDebug;
+    }
+
+    shared static this()
+    {
+        _qtdDebug = new QtdDebug;
+    }
+}
+
--- a/d2/qtd/MOC.d	Wed Jul 07 22:54:12 2010 +0100
+++ b/d2/qtd/MOC.d	Thu Jul 08 17:20:02 2010 +0300
@@ -15,6 +15,8 @@
 
 import qt.core.QString;
 
+private:
+
 /**
    Utils.
  */
@@ -265,7 +267,7 @@
 
     FunctionDef[] propertyList, enumList, constructorList;
     int index = 12;
-    gen.output ~= "private static const uint[] qt_meta_data = [\n";
+    gen.output ~= "private static immutable uint[] qt_meta_data = [\n";
     gen.output ~= format_ctfe("\n // content:\n");
     gen.output ~= format_ctfe("    ${},       // revision\n", 2);
     gen.output ~= format_ctfe("    ${},       // classname\n", strreg(gen, gen.cdef.classname));
@@ -332,7 +334,7 @@
 //
 // Build stringdata array
 //
-    gen.output ~= "private static const string qt_meta_stringdata = \n";
+    gen.output ~= "private static immutable char[] qt_meta_stringdata = \n";
     gen.output ~= format_ctfe("    \"");
     int col = 0;
     int len = 0;
@@ -405,13 +407,9 @@
     return res;
 }
 
-template Q_OBJECT_BIND()
-{
-}
-
 // ------------------------------------------------------------------------------------------
 
-string generateSignalEmitters(uint signalCount)
+public string generateSignalEmitters(uint signalCount)
 {
     string res = "";
     foreach (i; 0..signalCount)
@@ -422,12 +420,12 @@
     return res;
 }
 
-private mixin template SlotAlias(alias slot)
+mixin template SlotAlias(alias slot)
 {
     mixin ("alias slot " ~ methodName!slot ~ ";");
 }
 
-string generateSlotAliases(uint slotCount)
+public string generateSlotAliases(uint slotCount)
 {
     string res = "";
     foreach(i; 0..slotCount)
@@ -438,7 +436,7 @@
     return res;
 }
 
-string generateMetaCall(string methodName, size_t argCount)
+public string generateMetaCall(string methodName, size_t argCount)
 {
     string res = "";
     foreach (i; 1..argCount)
@@ -454,7 +452,7 @@
     return res ~ ");\n";
 }
 
-string generateDispatchSwitch(size_t methodCount)
+public string generateDispatchSwitch(size_t methodCount)
 {
     string res = "switch(_id) {\n";
 
@@ -473,7 +471,7 @@
     return res ~ "}\n";
 }
 
-string generateMetaInfo(T)()
+public string generateMetaInfo(T)()
 {
     Generator gen;
 
@@ -488,13 +486,17 @@
     return gen.output;
 }
 
-mixin template Q_OBJECT()
+// TODO: move to a better place
+public mixin template Q_OBJECT()
 {
     import
         std.typetuple,
         std.traits,
         qtd.Marshal,
+        qtd.Signal,
         qtd.meta.Runtime,
+        qtd.MOC,
+        qt.core.QMetaObject,
         qt.core.QString; // for QStringUtil.toNative
 
 public: // required to override the outside scope protection.
@@ -510,7 +512,7 @@
     //pragma(msg, generateMetaInfo!This());
     mixin (generateMetaInfo!This());
 
-    protected int qt_metacall(QMetaObject.Call _c, int _id, void **_a)
+    protected int qt_metacall(MetaCall _c, int _id, void **_a)
     {
         _id = super.qt_metacall(_c, _id, _a);
 
@@ -519,7 +521,7 @@
             if (_id < 0)
                 return _id;
 
-            if (_c == QMetaObject.Call.InvokeMetaMethod) {
+            if (_c == MetaCall.InvokeMetaMethod) {
                 //pragma(msg, generateDispatchSwitch(methods.length));
                 mixin (generateDispatchSwitch(methods.length));
             }
@@ -543,7 +545,7 @@
 
     __gshared static QMetaObjectNative nativeStaticMetaObject_;
 
-    static void* qtd_nativeStaticMetaObject()
+    static void* qtdNativeStaticMetaObject()
     {
         alias BaseClassesTuple!(This)[0] Base;
 
--- a/d2/qtd/QMetaTypeImpl.d	Wed Jul 07 22:54:12 2010 +0100
+++ b/d2/qtd/QMetaTypeImpl.d	Thu Jul 08 17:20:02 2010 +0300
@@ -19,11 +19,16 @@
 }
 
 /**
- */
+    Default implementation of constructors/destructors
+    registered with Qt when qtd_qRegisterMetaType is called
+    for a T.
+
+    For Ts that are passed-by-reference objects, we follow Qt's convention and
+    allocate/copy references, not objects. To override this behavior,
+    supply qtd_qRegisterMetaType with a custom constructor/destructor implementation.
+*/
 template MetaTypeOps(T)
 {
-    // Note that in case of byref objects we follow Qt's convention and
-    // allocate/copy references, not objects.
     static void* construct(void* copy)
     {
         auto T* p = cast(T*)GC.malloc(T.sizeof);
@@ -51,7 +56,7 @@
 
     static void destroy(void* ptr)
     {
-        // Run destructors for value types. Let the GC reclaim the memory.
+        // Run destructors for structs. Let the GC reclaim the memory.
         static if (is(T == struct) && __traits(compiles, T.__dtor))
             (cast(T*)ptr).__dtor;
     }
@@ -63,16 +68,14 @@
 {
     void save(QDataStream ds, const void* data)
     {
-        writeln("Saving ", ds.__nativeId, " ", data);
     }
 
     void load(QDataStream ds, void* data)
     {
-        writeln("Loading ", ds.__nativeId, " ", data);
     }
 }
 
-// TODO: only GNU C++ is supported
+// TODO: only GNU C++ x86 is supported
 private template typeOpShim(alias op)
 {
     extern(C) void typeOpShim()
@@ -97,13 +100,14 @@
     if (!name.length)
         name = typeid(T).toString; //TODO: use compile time full name
 
-    return qtd_registerType(toStringz(name), &typeOpShim!(ops!T.destroy), &typeOpShim!(ops!T.construct));
+    return qtd_QMetaType_registerType(toStringz(name), &typeOpShim!(ops!T.destroy), &typeOpShim!(ops!T.construct));
 }
 
 version (QtdUnittest)
 {
     unittest
     {
+        /+
         static class A
         {
             int x;
@@ -189,6 +193,7 @@
         assert(paa2 !is &aa);
         assert(*paa2 == aa);
         QMetaType.destroy(aaId, paa);
+        +/
     }
 }
 
@@ -223,25 +228,22 @@
 
     static void save(void* ds, const void* data)
     {
-        scope dataStream = new QDataStream(ds, QtdObjectFlags.nativeOwnership);
+        scope dataStream = new QDataStream(ds, QtdObjectInitFlags.onStack);
         ops!T.save(dataStream, data);
     }
 
     static void load(void* ds, void* data)
     {
-        scope dataStream = new QDataStream(ds, QtdObjectFlags.nativeOwnership);
+        scope dataStream = new QDataStream(ds, QtdObjectInitFlags.onStack);
         ops!T.load(dataStream, data);
     }
 
-    qtd_registerStreamOperators(toStringz(name), &streamOpShim!save, &streamOpShim!load);
+    qtd_QMetaType_registerStreamOperators(toStringz(name), &streamOpShim!save, &streamOpShim!load);
 }
 
-/**
- */
-private extern(C)
+extern(C)
 {
-    void qtd_registerStreamOperators(in char *typeName, VoidFunc saveOp, VoidFunc loadOp);
-    int qtd_registerType(in char* namePtr, VoidFunc ctor, VoidFunc dtor);
+    void qtd_QMetaType_registerStreamOperators(in char *typeName, VoidFunc saveOp, VoidFunc loadOp);
+    int qtd_QMetaType_registerType(in char* namePtr, VoidFunc ctor, VoidFunc dtor);
     int qtd_QMetaType_type_nativepointerchar(in char* typeName0);
 }
-
--- a/d2/qtd/QtdObject.d	Wed Jul 07 22:54:12 2010 +0100
+++ b/d2/qtd/QtdObject.d	Thu Jul 08 17:20:02 2010 +0300
@@ -1,75 +1,330 @@
 /**
 *
-*  Copyright: Copyright QtD Team, 2008-2009
-*  License: <a href="http://www.boost.org/LICENSE_1_0.txt>Boost License 1.0</a>
-*
-*  Copyright QtD Team, 2008-2009
-*  Distributed under the Boost Software License, Version 1.0.
-*  (See accompanying file boost-license-1.0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+*  Copyright: Copyright QtD Team, 2008-2010
+*  License: Boost License 1.0
+*  Authors: Max Samukha, Eldar Insafutdinov
 *
 */
 
 module qtd.QtdObject;
-import qtd.Core;
 
-enum QtdObjectFlags : ubyte
+import
+    core.memory,
+    std.bitmanip,
+    qtd.Core,
+    qtd.Debug,
+    qtd.meta.Runtime;  
+
+/**
+    QtdObject initialization options.
+ */
+enum QtdObjectInitFlags
 {
     none,
-    nativeOwnership           = 0x1,
-    dOwnership                = 0x2,
-    dynamicEntity             = 0x4
-    //gcManaged               = 0x4
+    /// The wrapper is being created by user code.
+    createdByD              = 0x1,
+    /// The wrapper is being created with native ownership.
+    nativeOwnership         = 0x2,
+    /// The wrapper is allocated on stack.
+    onStack                 = 0x4
 }
 
-package abstract class QtdObject
+/**
+ */
+enum QtdObjectOwnership
 {
-    protected QtdObjectFlags __flags_;
-    void* __nativeId;
+    ///
+    native,
+    ///
+    d
+}
 
-    this(void* nativeId, QtdObjectFlags flags = QtdObjectFlags.none)
+/**
+ */
+struct QtdObjectFlags
+{
+    mixin (bitfields!(
+        bool, "nativeDeleteDisabled"        , 1,
+        bool, "wrapperDeleteDisabled"       , 1,
+        bool, "createdByD"                  , 1,
+        bool, "pinned"                      , 1,
+        bool, "isQObject"                   , 1,
+        bool, "polymorphic"                 , 1,
+        bool, "onStack"                     , 1,
+        int , "reserved"                    , 1
+    ));
+}
+
+
+/* package */ abstract class QtdObject
+{
+    alias typeof(this) This;
+
+    private
     {
-        __nativeId = nativeId;
-        __flags_ = flags;
+        void* _nativeId;
+        This _next;
+        This _prev;
+        __gshared static This _root;
     }
 
-    final QtdObjectFlags __flags()
+    protected QtdObjectFlags _flags;
+
+    /**
+     */
+    @property QtdObjectFlags qtdFlags()
     {
-        return __flags_;
+        return _flags;
     }
 
-    /+ final +/ void __setFlags(QtdObjectFlags flags, bool value)
+    /**
+     */
+    @property final const
     {
-        if (value)
-            __flags_ |= flags;
+        void* qtdNativeId()
+        {
+            return cast(void*)_nativeId;
+        }
+
+        void qtdNativeId(void* v)
+        {
+            unqual(_nativeId) = v;
+        }
+    }
+
+    this(void* nativeId, QtdObjectInitFlags initFlags = QtdObjectInitFlags.none)
+    {
+        _nativeId = nativeId;
+
+        if (initFlags & QtdObjectInitFlags.createdByD)
+            _flags.createdByD = true;
+
+        if (initFlags & QtdObjectInitFlags.nativeOwnership)
+            qtdSetOwnership(QtdObjectOwnership.native);
+
+        if (initFlags & QtdObjectInitFlags.onStack)
+        {
+            //assert(!_flags.isQObject);
+            assert(!(initFlags & QtdObjectInitFlags.nativeOwnership));
+
+            _flags.nativeDeleteDisabled = true;
+            _flags.wrapperDeleteDisabled = true;
+        }
+
+        mixin(debugHandler("onWrapperConstructed", "this"));
+    }
+
+    /**
+        Disables GC for this object;
+     */
+    // TODO: needs to be properly synchronized
+    final void qtdPin() const
+    {
+        assert(!_flags.pinned);
+        //GC.addRoot(cast(void*)this);
+
+        auto obj = unqual(this);
+
+        obj._next = _root;
+        _root = obj;
+        if (_next)
+            obj._next._prev = obj;
+
+        obj._flags.pinned = true;
+    }
+
+    /**
+        Multiple wrappers for a single native object may exist.
+        This function is used to test that this and the other wrapper point
+        to the same native object (identity test).
+
+        Note that wrappers for QObject instances and instances of classes
+        derived from QObject are always unique, therefore
+        the 'is' expression can be used instead of this function.
+     */
+    final bool isSame(const(QtdObject) other) const
+    {
+        return other !is null && (other is this || other.qtdNativeId == qtdNativeId);
+    }
+
+    /**
+        Enables GC for this object.
+     */
+    // TODO: needs to be properly synchronized
+    final void qtdUnpin() const
+    {
+        assert(_flags.pinned);
+        //GC.removeRoot(cast(void*)this);
+
+        auto obj = unqual(this);
+        if (_prev)
+            obj._prev._next = obj._next;
         else
-            __flags_ &= ~flags;
+            _root = obj._next;
+
+        if (_next)
+            obj._next._prev = obj._prev;
+
+        obj._flags.pinned = false;
+    }
+
+    /**
+        Sets the ownership of this object.
+        Setting the same ownership twice results in undefined behavior.
+        The function is not thread-safe.
+     */
+    void qtdSetOwnership(QtdObjectOwnership own) const
+    {
+        if (_flags.isQObject)
+            return;
+
+        assert(!_flags.onStack);
+        auto obj = unqual(this);
+
+        if (own == QtdObjectOwnership.native)
+        {
+            if (_flags.polymorphic && _flags.createdByD)
+                qtdPin();
+            else
+                obj._flags.nativeDeleteDisabled = true;
+        }
+        else if (own == QtdObjectOwnership.d)
+        {
+            if (_flags.polymorphic && _flags.createdByD)
+                qtdUnpin();
+            else
+                obj._flags.nativeDeleteDisabled = false;
+        }
+        else
+            assert(false);
+
+        mixin(debugHandler("onWrapperOwnershipChanged", "obj"));
     }
 
     // COMPILER BUG: 3206
-    protected void __deleteNative()
+    protected void qtdDeleteNative()
     {
         assert(false);
     }
 
     ~this()
     {
-        if (!(__flags_ & QtdObjectFlags.nativeOwnership))
+        mixin(debugHandler("onWrapperDestruction", "this"));
+
+        if (!_flags.nativeDeleteDisabled)
         {
             // avoid deleting D object twice.
-            __flags_ |= QtdObjectFlags.dOwnership;
-            __deleteNative;
+
+            _flags.wrapperDeleteDisabled = true;
+            qtdDeleteNative;
+
+            mixin(debugHandler("onNativeDeleted", "this"));
         }
+
+        if (_flags.pinned)
+            qtdUnpin();
+
+        mixin(debugHandler("onWrapperDestroyed", "this"));
     }
 }
 
+/**
+    Base class for polymorphic non-QObjects (TBD).
+ */
+/* package */ abstract class NonQObject : QtdObject
+{
+    alias NonQObjectMetaClass Meta;
+
+    this(void* nativeId, QtdObjectInitFlags initFlags)
+    {
+        _flags.polymorphic = true;
+        super(nativeId, initFlags);
+    }
+}
+
+/**
+    Base class for QtD meta-object classes.
+ */
+abstract class QtdMetaClass : MetaClass
+{
+    alias QtdObject function(void* nativeId, QtdObjectInitFlags initFlags) CreateWrapper;
+
+    private void* _nativeId;
+    protected CreateWrapper _createWrapper;
+
+    this() {}
+
+    /**
+     */
+    @property
+    void* nativeId()
+    {
+        return _nativeId;
+    }
+
+    void construct(T)()
+    {
+        super.construct!T();
+        _nativeId = T.qtdNativeStaticMetaObject();
+        _createWrapper = &T.qtdCreateWrapper;
+    }
+
+    abstract QtdObject getWrapper(void* nativeId, QtdObjectInitFlags initFlags = QtdObjectInitFlags.none);
+}
+
+/**
+    Meta-object class for non-QObject polymorphic classes.
+ */
+final class NonQObjectMetaClass : QtdMetaClass
+{
+    alias typeof(this) This;
+    alias createImpl!This create;
+
+    @property override This next()
+    {
+        return static_cast!This(super.next);
+    }
+
+    @property override This firstDerived()
+    {
+        return static_cast!This(super.firstDerived);
+    }
+
+    override QtdObject getWrapper(void* nativeId, QtdObjectInitFlags initFlags)
+    {
+        // traverse the inheritance tree to find a matching meta-object.
+        // if the exact match is not found, return the closest base.
+        This lookUp(This mo)
+        {
+            if (!qtdTypeInfosEqual(mo.nativeId, nativeId))
+            {
+                for (auto mo2 = mo.firstDerived; mo2 !is null; mo2 = mo2.next)
+                {
+                    mo2 = lookUp(mo2);
+                    if (mo != mo2)
+                        break;
+                }
+            }
+            return mo;
+        }
+
+        auto mo = lookUp(this);
+        return static_cast!NonQObject(mo._createWrapper(nativeId, initFlags));
+    }
+}
+
+extern (C) bool qtdTypeInfosEqual(void* info1, void* info2);
+
 mixin(qtdExport("void", "QtdObject_delete", "void* dId",
     q{
         auto obj = cast(QtdObject)dId;
 
-        if (!(obj.__flags & QtdObjectFlags.dOwnership))
+        mixin(debugHandler("onDeletingWrapperFromNative", "dId"));
+
+        if (!obj._flags.wrapperDeleteDisabled)
         {
             // Avoid deleting native object twice
-            obj.__setFlags(QtdObjectFlags.nativeOwnership, true);
+            obj._flags.nativeDeleteDisabled = true;
             delete obj;
         }
     }));
--- a/d2/qtd/Signal.d	Wed Jul 07 22:54:12 2010 +0100
+++ b/d2/qtd/Signal.d	Thu Jul 08 17:20:02 2010 +0300
@@ -105,9 +105,12 @@
            _a[${0}] = cast(void*)&_tmp${0};
         }
         else static if (isQObjectType!(Args[${0}]) || isObjectType!(Args[${0}]))
-           _a[${0}] = _t${0} ? &(_t${0}.__nativeId) : cast(void*)&_t${0};
+        {
+            void* _tmp${0} = _t${0} ? _t${0}.qtdNativeId : null;
+            _a[${0}] =  &_tmp${0};
+        }
         else static if (isValueType!(Args[${0}]))
-           _a[${0}] = _t${0}.__nativeId;
+           _a[${0}] = _t${0}.qtdNativeId;
         else
            _a[${0}] = cast(void*)&_t${0};
 
@@ -256,4 +259,4 @@
 template methodName(alias method)
 {
     enum methodName = removePrefix(__traits(identifier, method));
-}
\ No newline at end of file
+}
--- a/d2/qtd/meta/Compiletime.d	Wed Jul 07 22:54:12 2010 +0100
+++ b/d2/qtd/meta/Compiletime.d	Thu Jul 08 17:20:02 2010 +0300
@@ -313,6 +313,8 @@
 
 private mixin template AttributeImpl(alias symbol, string attrClass, AttributeOptions opts, size_t index, A...)
 {
+    import std.typetuple;
+
     private enum attrId = attributeId!(symbol, index) ~ (opts & AttributeOptions.inner ? "_inner" : "");
 
     static if (is(typeof(mixin(attrId))))
--- a/d2/qtd/meta/Runtime.d	Wed Jul 07 22:54:12 2010 +0100
+++ b/d2/qtd/meta/Runtime.d	Thu Jul 08 17:20:02 2010 +0300
@@ -91,6 +91,9 @@
     }
 }
 
+/**
+    All meta-object classes inherit from this base class.
+ */
 abstract class MetaBase
 {
     alias typeof(this) This;
@@ -123,7 +126,7 @@
             {
                 alias attr[2] MA;
                 alias TypeTuple!(attr[0..2], attr[3..$]) args;
-                attributes ~= MA /*COMPILER BUG: tuple element as tuple*/[0].create!args();
+                attributes ~= MA /*COMPILER BUG: tuple element as tuple*/[0].create(args);
             }
         }
     }
@@ -238,7 +241,7 @@
 
     static struct AllMembersRange
     {
-        public //private
+        private
         {
             This metaClass_;
             MetaBase[] members_;
@@ -249,10 +252,7 @@
                 {
                     metaClass_ = metaClass_.base_;
                     if (!metaClass_)
-                    {
-                        members_ = null;
                         return;
-                    }
                 }
 
                 members_ = metaClass_.members_;
@@ -345,6 +345,7 @@
     /* internal */ void construct(T : Object)()
     {
         super.construct!T();
+        classInfo_ = T.classinfo;
         static if (!is(T == Object))
         {
             alias BaseClassesTuple!(T)[0] Base;
@@ -353,7 +354,6 @@
             next_ = base_.firstDerived_;
             base_.firstDerived_ = this;
         }
-        classInfo_ = T.classinfo;
     }
 
     /**
@@ -393,20 +393,9 @@
         m = sharedM;
     }
 
-    assert (m is sharedM);
     return m;
 }
 
-version (QtdUnittest) unittest
-{
-    class A
-    {
-    }
-
-    auto m = meta!A;
-    assert(m is meta!A);
-}
-
 /**
  */
 // only classes and structs for now
@@ -438,14 +427,13 @@
         super(name, opts);
     }
 
-    static MetaVariantAttribute create(string name, AttributeOptions opts, A...)()
+    static MetaVariantAttribute create(A...)(string name, AttributeOptions opts, A args)
     {
         auto ret = new This(name, opts);
+
         foreach(i, _; A)
-        {
-            static if (__traits(compiles, { ret.values ~= Variant(A[i]); } ))
-                ret.values ~= Variant(A[i]);
-        }
+            ret.values ~= Variant(args[i]);
+
         return ret;
     }
 }
@@ -464,42 +452,50 @@
         super(name, opts);
     }
 
-    static This create(string name, AttributeOptions opts, A...)()
+    static This create(A...)(string name, AttributeOptions opts, A args)
     {
         auto ret = new This(name, opts);
         foreach(i, _; A)
-        {
-            static if (i % 2 == 0 && __traits(compiles, { ret.values[A[i]] = Variant(A[i + 1]); } ))
-                ret.values[A[i]] = Variant(A[i + 1]); // PHOBOS BUG: phobos asserts on this
-        }
+            ret.values[args[i]] = Variant(args[i + 1]); // PHOBOS BUG: phobos asserts on this
+
         return ret;
     }
 }
 
 version(QtdUnittest) unittest
 {
+    enum x = 42;
     static void foo() {}
 
     static class C
     {
-        mixin InnerAttribute!("variantAttribute", MetaVariantAttribute, "22", foo, 33);
+
+        mixin InnerAttribute!("variantAttribute", MetaVariantAttribute, "22", x, 33);
+
+        /+ PHOBOS BUG: variant is unusable with AAs
         mixin InnerAttribute!("variantDictAttribute", MetaVariantDictAttribute,
-            //"a", "33", // PHOBOS BUG: variant is unusable with AAs
-            "b", foo
-            //"c", 44
+            "a", "33",
+            "b", 44,
+            "c", x
             );
+        +/
     }
 
     auto attrs = meta!(C).attributes;
-    assert(attrs.length == 2);
+    assert(attrs.length == 1);
     auto attr = cast(MetaVariantAttribute)attrs[0];
 
     assert(attr.name == "variantAttribute");
     assert(attr.values[0] == "22");
-    assert(attr.values[1] == 33);
+    assert(attr.values[1] == x);
+    assert(attr.values[2] == 33);
+
+    /+
 
     auto attr2 = cast(MetaVariantDictAttribute) attrs[1];
     assert(attr2.name == "variantDictAttribute");
     //assert(attr2.values["a"] == "33");
-    //assert(attr2.values["c"] == 44);
+    //assert(attr2.values["b"] == 44);
+    //assert(attr2.values["c"] == x);
+    +/
 }
--- a/demos/interview/main.d	Wed Jul 07 22:54:12 2010 +0100
+++ b/demos/interview/main.d	Thu Jul 08 17:20:02 2010 +0300
@@ -34,10 +34,7 @@
 ** contact the sales department at qt-sales@nokia.com.
 **
 ****************************************************************************/
-version(D_Version2)
-    import model;
-else
-    import model_d1;
+import model;
 
 import qt.gui.QApplication;
 import qt.gui.QItemSelectionModel;
@@ -49,10 +46,14 @@
 import qt.gui.QListView;
 import qt.gui.QIcon;
 import qt.gui.QPixmap;
+import std.stdio;
 
 int main(string[] args)
-{
+{    
+    writeln("Interview");
+        
     scope app = new QApplication(args);
+    
     scope page = new QSplitter;
 
     scope data = new Model(1000, 10); //parent = page
--- a/examples/draganddrop/dropsite/droparea.d	Wed Jul 07 22:54:12 2010 +0100
+++ b/examples/draganddrop/dropsite/droparea.d	Thu Jul 08 17:20:02 2010 +0300
@@ -46,79 +46,79 @@
 class DropArea : public QLabel
 {
 public:
-	this(QWidget parent = null)
-	{
-		super(parent);
+    this(QWidget parent = null)
+    {
+        super(parent);
 
-		setMinimumSize(200, 200);
-		setFrameStyle(QFrame.Sunken | QFrame.StyledPanel);
-		setAlignment(Qt.AlignCenter);
-		setAcceptDrops(true);
-		setAutoFillBackground(true);
-		clearArea();
-	}
-   
-	void slot_clearArea()
-	{
-		setText(tr("<drop content>"));
-		setBackgroundRole(QPalette.Dark);
+        setMinimumSize(200, 200);
+        setFrameStyle(QFrame.Sunken | QFrame.StyledPanel);
+        setAlignment(Qt.AlignCenter);
+        setAcceptDrops(true);
+        setAutoFillBackground(true);
+        clearArea();
+    }
 
-		changed(null);
-	}
+    void slot_clearArea()
+    {
+        setText(tr("<drop content>"));
+        setBackgroundRole(QPalette.Dark);
 
-	final void signal_changed(QMimeData);
-	
+        changed(null);
+    }
+
+    final void signal_changed(QMimeData);
+
 protected:
-	void dragEnterEvent(QDragEnterEvent event)
-	{
-		setText(tr("<drop content>"));
-		setBackgroundRole(QPalette.Highlight);
+    void dragEnterEvent(QDragEnterEvent event)
+    {
+        setText(tr("<drop content>"));
+        setBackgroundRole(QPalette.Highlight);
 
-		event.acceptProposedAction();
-		changed(event.mimeData);
-	}
-	
-	void dragMoveEvent(QDragMoveEvent event)
-	{
-		event.acceptProposedAction();
-	}
-	
-	void dragLeaveEvent(QDragLeaveEvent event)
-	{
-		clearArea();
-		event.accept();
-	}
-	
-	void dropEvent(QDropEvent event)
-	{
-		QMimeData mimeData = event.mimeData();
+        event.acceptProposedAction();
+        changed(event.mimeData);
+    }
 
-		if (mimeData.hasImage()) {
-			setPixmap(new QPixmap(mimeData.imageData));
-		} else if (mimeData.hasHtml()) {
-			setText(mimeData.html());
-			setTextFormat(Qt.RichText);
-		} else if (mimeData.hasText()) {
-			setText(mimeData.text());    
-			setTextFormat(Qt.PlainText);
-		} else if (mimeData.hasUrls()) {
-			auto urlList = mimeData.urls();
-			string text;
-			for (int i = 0; i < urlList.length && i < 32; ++i) {
-				text ~= urlList[i].path() ~ "\n";
-			}
-			setText(text);
-		} else {
-			setText(tr("Cannot display data"));
-		}
+    void dragMoveEvent(QDragMoveEvent event)
+    {
+        event.acceptProposedAction();
+    }
 
-		setBackgroundRole(QPalette.Dark);
-		event.acceptProposedAction();
-	}
+    void dragLeaveEvent(QDragLeaveEvent event)
+    {
+        clearArea();
+        event.accept();
+    }
+
+    void dropEvent(QDropEvent event)
+    {
+        QMimeData mimeData = event.mimeData();
+
+        if (mimeData.hasImage()) {
+            setPixmap(new QPixmap(mimeData.imageData));
+        } else if (mimeData.hasHtml()) {
+            setText(mimeData.html());
+            setTextFormat(Qt.RichText);
+        } else if (mimeData.hasText()) {
+            setText(mimeData.text());
+            setTextFormat(Qt.PlainText);
+        } else if (mimeData.hasUrls()) {
+            auto urlList = mimeData.urls();
+            string text;
+            for (int i = 0; i < urlList.length && i < 32; ++i) {
+                text ~= urlList[i].path() ~ "\n";
+            }
+            setText(text);
+        } else {
+            setText(tr("Cannot display data"));
+        }
+
+        setBackgroundRole(QPalette.Dark);
+        event.acceptProposedAction();
+    }
 
 private:
-	QLabel label;
-    
+    QLabel label;
+
     mixin Q_OBJECT;
 }
 
--- a/examples/draganddrop/dropsite/dropsitewindow.d	Wed Jul 07 22:54:12 2010 +0100
+++ b/examples/draganddrop/dropsite/dropsitewindow.d	Thu Jul 08 17:20:02 2010 +0300
@@ -53,101 +53,114 @@
 import droparea;
 
 
+import std.stdio; //TODO: remove
+
+
 class DropSiteWindow : public QWidget
 {
 public:
 
-	this()
-	{
-		abstractLabel = new QLabel(tr("This example accepts drags from other "
-			"applications and displays the MIME types "
-			"provided by the drag object."));
+    this()
+    {
+        abstractLabel = new QLabel(tr("This example accepts drags from other "
+            "applications and displays the MIME types "
+            "provided by the drag object."));
 
-		abstractLabel.setWordWrap(true);
-		abstractLabel.adjustSize();
+        abstractLabel.setWordWrap(true);
+        abstractLabel.adjustSize();
 
-		dropArea = new DropArea;
-		connect(dropArea, "changed", this, "updateFormatsTable");
+        dropArea = new DropArea;
+        connect(dropArea, "changed", this, "updateFormatsTable");
 
-		string[] labels;
-		labels ~= tr("Format");
-		labels ~= tr("Content");
+        string[] labels;
+        labels ~= tr("Format");
+        labels ~= tr("Content");
 
-		formatsTable = new QTableWidget;
-		formatsTable.setColumnCount(2);
-		formatsTable.setEditTriggers(QAbstractItemView.NoEditTriggers);
-		formatsTable.setHorizontalHeaderLabels(labels.toQList());
-		formatsTable.horizontalHeader().setStretchLastSection(true);
+        formatsTable = new QTableWidget;
+        formatsTable.setColumnCount(2);
+        formatsTable.setEditTriggers(QAbstractItemView.NoEditTriggers);
+        formatsTable.setHorizontalHeaderLabels(labels.toQList());
+        formatsTable.horizontalHeader().setStretchLastSection(true);
 
-		clearButton = new QPushButton(tr("Clear"));
-		quitButton = new QPushButton(tr("Quit"));
+        clearButton = new QPushButton(tr("Clear"));
+        quitButton = new QPushButton(tr("Quit"));
 
-		buttonBox = new QDialogButtonBox;
-		buttonBox.addButton(clearButton, QDialogButtonBox.ActionRole);
-		buttonBox.addButton(quitButton, QDialogButtonBox.RejectRole);
+        buttonBox = new QDialogButtonBox;
+        buttonBox.addButton(clearButton, QDialogButtonBox.ActionRole);
+        buttonBox.addButton(quitButton, QDialogButtonBox.RejectRole);
 
-		connect(quitButton, "pressed", this, "close");
-		connect(clearButton, "pressed", dropArea, "clearArea");
+        connect(quitButton, "pressed", this, "close");
+        connect(clearButton, "pressed", dropArea, "clearArea");
 
-		QVBoxLayout mainLayout = new QVBoxLayout;
-		mainLayout.addWidget(abstractLabel);
-		mainLayout.addWidget(dropArea);
-		mainLayout.addWidget(formatsTable);
-		mainLayout.addWidget(buttonBox);
-		setLayout(mainLayout);
+        QVBoxLayout mainLayout = new QVBoxLayout;
+        mainLayout.addWidget(abstractLabel);
+        mainLayout.addWidget(dropArea);
+        mainLayout.addWidget(formatsTable);
+        mainLayout.addWidget(buttonBox);
+        setLayout(mainLayout);
 
-		setWindowTitle(tr("Drop Site"));
-		setMinimumSize(350, 500);
-	}
+        setWindowTitle(tr("Drop Site"));
+        setMinimumSize(350, 500);
+    }
 
-	void slot_updateFormatsTable(QMimeData mimeData)
-	{
-		formatsTable.setRowCount(0);
-		if (!mimeData)
-			return;
+    void slot_updateFormatsTable(QMimeData mimeData)
+    {
+        formatsTable.setRowCount(0);
+        if (!mimeData)
+            return;
 
-		foreach (string format; mimeData.formats()) {
-			QTableWidgetItem formatItem = new QTableWidgetItem(format);
-			formatItem.setFlags(Qt.ItemIsEnabled);
-			formatItem.setTextAlignment(Qt.AlignTop | Qt.AlignLeft);
+        foreach (string format; mimeData.formats()) {
 
-			string text;
-			if (format == "text/plain") {
-				text = strip(mimeData.text());
-			} else if (format == "text/html") {
-				text = strip(mimeData.html());
-			} else if (format == "text/uri-list") {
-				auto urlList = mimeData.urls();
-				for (int i = 0; i < urlList.length && i < 32; ++i) {
-					string url = urlList[i].path();
-					text ~= url ~ " ";
-				}
-			} else {
-				QByteArray data = mimeData.data(format);
-				for (int i = 0; i < data.size() && i < 32; ++i) {
-					string hex = toupper(std.string.format("%x", data.at(i)));
-					text ~= hex ~ " ";
-				}
-			}
+            writeln("Point 1");
+            QTableWidgetItem formatItem = new QTableWidgetItem(format);
+            formatItem.setFlags(Qt.ItemIsEnabled);
+            formatItem.setTextAlignment(Qt.AlignTop | Qt.AlignLeft);
 
-			int row = formatsTable.rowCount();
-			formatsTable.insertRow(row);
-			formatsTable.setItem(row, 0, new QTableWidgetItem(format));
-			formatsTable.setItem(row, 1, new QTableWidgetItem(text));
-		}
+            string text;
+            if (format == "text/plain") {
+                text = strip(mimeData.text());
+            } else if (format == "text/html") {
+                text = strip(mimeData.html());
+            } else if (format == "text/uri-list") {
+                auto urlList = mimeData.urls();
+                for (int i = 0; i < urlList.length && i < 32; ++i) {
+                    string url = urlList[i].path();
+                    text ~= url ~ " ";
+                }
+            } else {
+                QByteArray data = mimeData.data(format);
+                for (int i = 0; i < data.size() && i < 32; ++i) {
+                    string hex = toupper(std.string.format("%x", data.at(i)));
+                    text ~= hex ~ " ";
+                }
+            }
 
-		formatsTable.resizeColumnToContents(0);
-	}
+            int row = formatsTable.rowCount();
+            formatsTable.insertRow(row);
+
+            writeln("Point 2");
+            formatsTable.setItem(row, 0, new QTableWidgetItem(format));
+            writeln("Point 3");
+            formatsTable.setItem(row, 1, new QTableWidgetItem(text));
+        }
+
+        formatsTable.resizeColumnToContents(0);
+    }
+
+    ~this()
+    {
+        writeln("deleting dropsitewindow");
+    }
 
 private:
 
-	DropArea dropArea;
-	QLabel abstractLabel;
-	QTableWidget formatsTable;
+    DropArea dropArea;
+    QLabel abstractLabel;
+    QTableWidget formatsTable;
 
-	QPushButton clearButton;
-	QPushButton quitButton;
-	QDialogButtonBox buttonBox;
+    QPushButton clearButton;
+    QPushButton quitButton;
+    QDialogButtonBox buttonBox;
 
     mixin Q_OBJECT;
 }
--- a/examples/tutorials/tutorial/t1/main.d	Wed Jul 07 22:54:12 2010 +0100
+++ b/examples/tutorials/tutorial/t1/main.d	Thu Jul 08 17:20:02 2010 +0300
@@ -40,8 +40,9 @@
 
 int main(string[] args)
 {
-    QApplication app = new QApplication(args);
-    QPushButton hello = new QPushButton("Hello world!");
+    scope app = new QApplication(args);
+    scope hello = new QPushButton("Hello world!");
     hello.show();
+
     return app.exec();
 }
--- a/generator/containergenerator.cpp	Wed Jul 07 22:54:12 2010 +0100
+++ b/generator/containergenerator.cpp	Thu Jul 08 17:20:02 2010 +0300
@@ -400,7 +400,7 @@
         d_type = cls_name;
         if (centry->designatedInterface())
             d_type = centry->designatedInterface()->name();
-        nativeId = ".__nativeId";
+        nativeId = ".qtdNativeId";
     }
 
     if (centry->designatedInterface()) {
--- a/generator/dgenerator.cpp	Wed Jul 07 22:54:12 2010 +0100
+++ b/generator/dgenerator.cpp	Thu Jul 08 17:20:02 2010 +0300
@@ -492,9 +492,9 @@
 static QString function_call_for_ownership(TypeSystem::Ownership owner)
 {
     if (owner == TypeSystem::CppOwnership) {
-        return "__setFlags(QtdObjectFlags.nativeOwnership, true)";
+        return "qtdSetOwnership(QtdObjectOwnership.native)";
     } else /* qtd 2 if (owner == TypeSystem::TargetLangOwnership) */ {
-        return "__setFlags(QtdObjectFlags.nativeOwnership, false)";
+        return "qtdSetOwnership(QtdObjectOwnership.d)";
     }/* else if (owner == TypeSystem::DefaultOwnership) {
         return "__no_real_delete = false";
 
@@ -788,7 +788,7 @@
     bool arg_written = false;
 
     if (!d_function->isConstructor() && !d_function->isStatic()) {
-        s << "(cast(" << d_function->ownerClass()->name() << ")this).__nativeId";
+        s << "qtdNativeId";
         arg_written = true;
     }
 
@@ -826,7 +826,7 @@
             QString arg_name = arg->argumentName();
 
             if (type->isVariant())
-                s << arg_name << " is null ? null : " << arg_name << ".__nativeId";
+                s << arg_name << " is null ? null : " << arg_name << ".qtdNativeId";
             else if (te->designatedInterface())
                 s << arg_name << " is null ? null : " << arg_name << ".__ptr_" << te->designatedInterface()->name();
             else if (modified_type == "string" /* && type->fullName() == "char" */) {
@@ -856,9 +856,9 @@
                 } // else if (value type is abstract) then we will get a null pointer exception, which is all right
 
                 if(dVersion == 2 && type->isConstant())
-                    s << "(cast(" << type->name() << ")" << arg_name << ").__nativeId";
+                    s << "(cast(" << type->name() << ")" << arg_name << ").qtdNativeId";
                 else
-                    s << arg_name << ".__nativeId";
+                    s << arg_name << ".qtdNativeId";
             }
         }
     }
@@ -931,7 +931,7 @@
             s << "new QVariant(ret);" << endl;
 
         if (return_type->isNativePointer() && return_type->typeEntry()->isValue())
-            s << "new " << return_type->name() << "(ret, QtdObjectFlags.nativeOwnership);" << endl;
+            s << "new " << return_type->name() << "(ret, QtdObjectInitFlags.nativeOwnership);" << endl;
 
         if (return_type->isObject()) {
             s << "qtd_" << return_type->name() << "_from_ptr(ret);" << endl << endl;
@@ -1715,9 +1715,9 @@
 
     if (d_class->isDestructorBase())
     {
-        s << INDENT << "protected override void __deleteNative() {" << endl;
+        s << INDENT << "protected override void qtdDeleteNative() {" << endl;
         {
-            s << INDENT << "qtd_" << d_class->name() << "_delete(__nativeId);" << endl;
+            s << INDENT << "    qtd_" << d_class->name() << "_delete(qtdNativeId);" << endl;
         }
         s << INDENT << "}" << endl << endl;
 
@@ -1731,12 +1731,12 @@
     }
 }
 
-void DGenerator::writeFlagsSetter(QTextStream &s, const AbstractMetaClass *d_class)
+void DGenerator::writeOwnershipSetter(QTextStream &s, const AbstractMetaClass *d_class)
 {
     if (d_class->isInterface())
-        s << INDENT << "void __setFlags(QtdObjectFlags flags, bool val);";
+        s << INDENT << "void qtdSetOwnership(QtdObjectOwnership own) const;";
     else if (!d_class->isNamespace()) // COMPILER BUG:
-        s << INDENT << "void __setFlags(QtdObjectFlags flags, bool val) { super.__setFlags(flags, val); }";
+        s << INDENT << "void qtdSetOwnership(QtdObjectOwnership own) const { super.qtdSetOwnership(own); }";
 }
 
 void DGenerator::writeSignalHandlers(QTextStream &s, const AbstractMetaClass *d_class)
@@ -1796,7 +1796,7 @@
                     if(ctype->isAbstract())
                         type_name = type_name + "_ConcreteWrapper";
                     s << INDENT << "scope " << arg_name << " = new " << type_name
-                                << "(cast(void*)(" << arg_ptr << "), QtdObjectFlags.nativeOwnership);" << endl;
+                                << "(cast(void*)(" << arg_ptr << "), QtdObjectInitFlags.onStack);" << endl;
                 }
                 s << endl;
             }
@@ -1951,18 +1951,21 @@
     if (!m_isRecursive) {
         s << "public import qt.QGlobal;" << endl
           << "public import qt.core.Qt;" << endl
-          << "private import qtd.QtdObject;" << endl
-          << "private import qt.core.QString;" << endl
-          << "private import qtd.Array;" << endl
-          << "private import qt.core.QList;" << endl;
+          << "import qtd.QtdObject;" << endl
+          << "import qt.core.QString;" << endl
+          << "import qtd.Array;" << endl
+          << "import qt.core.QList;" << endl;
         if (d_class->isQObject()) {
-            s << "public import qtd.Signal;" << endl
-              << "public import qtd.MOC;" << endl
-              << "public import qt.core.QMetaObject;" << endl
-              << "import qtd.meta.Runtime;";
+            // TODO: just move those to a separate module publicly imported by QObject
+            // or to QObject itself
+            s << "public import qtd.MOC : Q_OBJECT;" << endl
+
+              << "import qtd.Signal;" << endl
+              << "import qt.core.QMetaObject;" << endl
+              << "import qtd.meta.Runtime;" << endl;
 
             if (d_class->name() != "QObject")
-                s << "public import qt.core.QObject;" << endl;
+                s << "import qt.core.QObject;" << endl;
         }
 
         // qtd2 hack!
@@ -2314,44 +2317,36 @@
           << INDENT << "public "
           << "this";
 
-
-        Indentation indent(INDENT);
-
-        s << "(void* native_id, QtdObjectFlags flags = QtdObjectFlags.none) {" << endl
-          << INDENT << "super(native_id, flags);" << endl;
-
-        if (d_class->name() == "QObject")
+        s << "(void* nativeId, QtdObjectInitFlags initFlags = QtdObjectInitFlags.none) {" << endl;
+
         {
-            // To prevent GC from collecting the object, add it to the statically rooted linked list
-            s << INDENT << "    __next = __root;" << endl
-            << INDENT << "    __root = this;" << endl
-            << INDENT << "    if (__next) {" << endl
-            << INDENT << "        __next.__prev = this;" << endl
-            << INDENT << "    }" << endl << endl;
-        }
-
-        /*
-        if (cpp_shared) {
-            if (d_class->generateShellClass() && !d_class->isInterface())
-                s << INDENT << "if (!static_inited)" << endl
-                  << INDENT << "    static_init_" << d_class->name() << "();" << endl << endl;
-        }
-        */
-
-
-        // pointers to native interface objects for classes that implement interfaces
-        // initializing
-        interfaces = d_class->interfaces();
-        if (!interfaces.isEmpty()) {
-            for (int i=0; i<interfaces.size(); ++i) {
-                AbstractMetaClass *iface = interfaces.at(i);
-
-                s << INDENT << "    __m_ptr_" << iface->name() << " = qtd_" << d_class->name() << "_cast_to_" << iface->qualifiedCppName()
-                  << "(__nativeId);" << endl;
+            Indentation indent(INDENT);
+
+            if (d_class->name() == "QObject") {
+                s << INDENT << "//assert (!(initFlags & QtdObjectInitFlags.onStack));" << endl
+                  << INDENT << "qtdPin();" << endl
+                  << INDENT << "_flags.isQObject = true;" << endl;
+            }
+
+            // only QObjects are handled polymorphically for now
+            if (d_class->name() == "QObject" /* d_class->polymorphicBase() == d_class */)
+                s << INDENT << "_flags.polymorphic = true;" << endl;
+
+            s << INDENT << "super(nativeId, initFlags);" << endl;
+
+            // pointers to native interface objects for classes that implement interfaces
+            // initializing
+            interfaces = d_class->interfaces();
+            if (!interfaces.isEmpty()) {
+                for (int i=0; i<interfaces.size(); ++i) {
+                    AbstractMetaClass *iface = interfaces.at(i);
+
+                    s << INDENT << "    __m_ptr_" << iface->name() << " = qtd_" << d_class->name() << "_cast_to_" << iface->qualifiedCppName()
+                      << "(nativeId);" << endl;
+                }
             }
         }
 
-
         s << INDENT << "}" << endl << endl;
 
         // pointers to native interface objects for classes that implement interfaces
@@ -2397,7 +2392,7 @@
 
 /* qtd    writeJavaLangObjectOverrideFunctions(s, d_class);
 */
-    writeFlagsSetter(s, d_class);
+    writeOwnershipSetter(s, d_class);
     s << "// Injected code in class" << endl;
     writeExtraFunctions(s, d_class);
 // qtd2    writeToStringFunction(s, d_class);
@@ -2438,9 +2433,9 @@
 
         {
             Indentation indent(INDENT);
-            QString hasShellFlag = d_class->generateShellClass() ? " | QtdObjectFlags.hasShell" : "";
-            s << INDENT << "public this(void* native_id, QtdObjectFlags flags = QtdObjectFlags.nativeOwnership) {" << endl
-              << INDENT << "    super(native_id, flags);" << endl << endl;
+
+            s << INDENT << "public this(void* native_id, QtdObjectInitFlags initFlags = QtdObjectInitFlags.nativeOwnership) {" << endl
+              << INDENT << "    super(native_id, initFlags);" << endl << endl;
 
             s << INDENT << "}" << endl << endl;
 
@@ -2677,11 +2672,11 @@
           << INDENT << "    auto d_obj_ref = cast (Object) d_obj;" << endl
           << INDENT << "    return cast(" << return_type_name << ") d_obj_ref;" << endl
           << INDENT << "} else {" << endl
-          << INDENT << "    auto return_value = new " << type_name << "(ret, QtdObjectFlags.nativeOwnership);" << endl
+          << INDENT << "    auto return_value = new " << type_name << "(ret, QtdObjectInitFlags.nativeOwnership);" << endl
           << INDENT << "    return return_value;" << endl
           << INDENT << "}" << endl;
     } else {
-        s << INDENT << "auto return_value = new " << type_name << "(ret, QtdObjectFlags.nativeOwnership);" << endl
+        s << INDENT << "auto return_value = new " << type_name << "(ret, QtdObjectInitFlags.nativeOwnership);" << endl
           << INDENT << "return return_value;" << endl;
     }
     s << "}" << endl << endl;
@@ -2691,12 +2686,12 @@
 {
     s << "extern(C) QMetaObjectNative* qtd_" << d_class->name() << "_staticMetaObject();" << endl << endl
       << "extern(C) void qtd_" << d_class->name() << "_createEntity(void* nativeId, void* dId);" <<  endl << endl
-      << "extern(C) int qtd_" << d_class->name() << "_qt_metacall(void *nativeId, QMetaObject.Call _c, int _id, void **_a);" << endl;
+      << "extern(C) int qtd_" << d_class->name() << "_qt_metacall(void *nativeId, MetaCall _c, int _id, void **_a);" << endl;
 
     QString prefix = cpp_shared ? "qtd_export_" : "qtd_";
 
     if (d_class->name() == "QObject") {
-        s << "extern(C) int " << prefix << "QObject_qt_metacall_dispatch(void *d_entity, QMetaObject.Call _c, int _id, void **_a) {" << endl
+        s << "extern(C) int " << prefix << "QObject_qt_metacall_dispatch(void *d_entity, MetaCall _c, int _id, void **_a) {" << endl
           << "    auto d_object = cast(QObject) d_entity;" << endl
           << "    return d_object.qt_metacall(_c, _id, _a);" << endl
           << "};" << endl << endl;
@@ -2747,12 +2742,11 @@
     }
     writeMetaMethodSignatures(s, "__slotSignatures", slot_funcs);
 
-    if (d_class->isAbstract())
-        s << "alias " << d_class->name() << "_ConcreteWrapper ConcreteType;" << endl;
+    QString concrete_name = d_class->isAbstract() ? d_class->name() + "_ConcreteWrapper" : d_class->name();
 
     if (!d_class->isFinal()) {
-        s << "    int qt_metacall(QMetaObject.Call _c, int _id, void **_a) {" << endl
-          << "        return qtd_" << d_class->name() << "_qt_metacall(__nativeId, _c, _id, _a);" << endl
+        s << "    int qt_metacall(MetaCall _c, int _id, void **_a) {" << endl
+          << "        return qtd_" << d_class->name() << "_qt_metacall(qtdNativeId, _c, _id, _a);" << endl
           << "    }" << endl << endl;
     }
 
@@ -2765,17 +2759,23 @@
       << "    }" << endl << endl
 
       << "    static " << d_class->name() << " __getObject(void* nativeId) {" << endl
-      << "        return static_cast!(" << d_class->name() << ")(staticMetaObject.getObject(nativeId));" << endl
+      << "        return static_cast!(" << d_class->name() << ")(staticMetaObject.getWrapper(nativeId));" << endl
       << "    }" << endl << endl
 
       << "    static void __createEntity(void* nativeId, void* dId) {" << endl
       << "        return qtd_" << d_class->name() << "_createEntity(nativeId, dId);" << endl
       << "    }" << endl << endl
 
-      << "    static void* qtd_nativeStaticMetaObject() {" << endl
+      << "    static void* qtdNativeStaticMetaObject() {" << endl
       << "        return qtd_" << d_class->name() << "_staticMetaObject();" << endl
       << "    }" << endl
 
+      << "    static QtdObject qtdCreateWrapper(void* nativeId, QtdObjectInitFlags initFlags) {" << endl
+      << "        auto obj = new " << concrete_name << "(nativeId, initFlags);" << endl
+      << "        " << d_class->name() << ".__createEntity(nativeId, cast(void*)obj);" << endl
+      << "        return obj;" << endl
+      << "    }" << endl << endl
+
       << "    static void _populateMetaInfo(QMetaObject mo) {" << endl
       << "        int index;" << endl << endl;
 
@@ -2826,8 +2826,6 @@
     }
 
     s  << "    }" << endl << endl;
-
-    s << INDENT << "mixin Q_OBJECT_BIND;" << endl << endl;
 }
 
 void DGenerator::marshalFromCppToD(QTextStream &s, const ComplexTypeEntry* ctype)
@@ -2996,7 +2994,7 @@
                     s << INDENT << "auto " << arg_name << "_d_qstr = QStringUtil(" << arg_name << ", true);" << endl
                       << INDENT << "string " << arg_name << "_d_ref = " << arg_name << "_d_qstr.toNativeString();";
                 } else if(type->isVariant())
-                    s << INDENT << "scope " << arg_name << "_d_ref = new QVariant(" << arg_name << ", QtdObjectFlags.nativeOwnership);";
+                    s << INDENT << "scope " << arg_name << "_d_ref = new QVariant(" << arg_name << ", QtdObjectInitFlags.onStack);";
                 else if (type->typeEntry()->isStructInD())
                     continue;
                 else if (!type->hasNativeId() && !(type->typeEntry()->isValue() && type->isNativePointer()))
@@ -3008,7 +3006,7 @@
                     const ComplexTypeEntry *ctype = static_cast<const ComplexTypeEntry *>(type->typeEntry());
                     if(ctype->isAbstract())
                         type_name = type_name + "_ConcreteWrapper";
-                    s << INDENT << "scope " << arg_name << "_d_ref = new " << type_name << "(" << arg_name << ", QtdObjectFlags.nativeOwnership);";
+                    s << INDENT << "scope " << arg_name << "_d_ref = new " << type_name << "(" << arg_name << ", QtdObjectInitFlags.onStack);";
                 }
                 else if (type->isQObject()) {
                     QString type_name = type->name();
@@ -3016,7 +3014,7 @@
                     if(ctype->isAbstract())
                         type_name = type_name + "_ConcreteWrapper";
 
-                    s << INDENT << "scope " << arg_name << "_d_ref = new " << type_name << "(" << arg_name << ", QtdObjectFlags.nativeOwnership);" << endl;
+                    s << INDENT << "scope " << arg_name << "_d_ref = new " << type_name << "(" << arg_name << ", QtdObjectInitFlags.onStack);" << endl;
                 }
                 s << endl;
             }
@@ -3098,7 +3096,7 @@
         if(f_type) {
             if(f_type->isObject() || f_type->isQObject() || f_type->isVariant() ||
                (f_type->isValue() && !f_type->typeEntry()->isStructInD())) {
-                QString native_id = "__nativeId";
+                QString native_id = "qtdNativeId";
                 if (f_type->typeEntry()->designatedInterface())
                     native_id =  "__ptr_" + f_type->typeEntry()->designatedInterface()->name();
                 s << INDENT << "return ret_value is null? null : ret_value." << native_id << ";" << endl;
@@ -3375,8 +3373,6 @@
     s << " {" << endl;
     {
         Indentation indent(INDENT);
-        bool shellClass = d_function->ownerClass()->generateShellClass();
-
         writeJavaCallThroughContents(s, d_function);
 
         // Write out expense checks if present...
@@ -3395,7 +3391,7 @@
             }
         }
 
-        s << INDENT << "this(ret);" << endl;
+        s << INDENT << "this(ret, QtdObjectInitFlags.createdByD);" << endl;
     }
     s << INDENT << "}" << endl << endl;
 
@@ -3466,7 +3462,7 @@
             s << endl
               << "    @Override" << endl
               << "    public String toString() {" << endl
-              << "        if (__nativeId == 0)" << endl
+              << "        if (qtdNativeId == 0)" << endl
               << "            throw new QNoNativeResourcesException(\"Function call on incomplete object of type: \" +getClass().getName());" << endl
               << "        return __qt_toString(nativeId());" << endl
               << "    }" << endl
--- a/generator/dgenerator.h	Wed Jul 07 22:54:12 2010 +0100
+++ b/generator/dgenerator.h	Thu Jul 08 17:20:02 2010 +0300
@@ -156,7 +156,7 @@
     AbstractMetaFunctionList generatedClassFunctions(const AbstractMetaClass *d_class);
 
     void writeDestructor(QTextStream &s, const AbstractMetaClass *d_class);
-    void writeFlagsSetter(QTextStream &s, const AbstractMetaClass *d_class);
+    void writeOwnershipSetter(QTextStream &s, const AbstractMetaClass *d_class);
     void writeSignalHandlers(QTextStream &s, const AbstractMetaClass *d_class);
     void writeEnumAliases(QTextStream &s, const AbstractMetaEnum *d_enum);
     void writeSignalSignatures(QTextStream &s, const AbstractMetaClass *d_class, AbstractMetaFunctionList signal_funcs);
--- a/generator/typesystem_core-java.java	Wed Jul 07 22:54:12 2010 +0100
+++ b/generator/typesystem_core-java.java	Thu Jul 08 17:20:02 2010 +0300
@@ -45,12 +45,12 @@
 import qt.core.*;
 
 class QObject___ extends QObject {
-    
+
     alias QMetaObject Meta;
-    
+
     /* TODO: test whether the linked list is really a better solution
     public bool __stackAllocated = false;
-    
+
     new(size_t size, void* p = null)
     {
         if (!p)
@@ -74,23 +74,17 @@
         }
     }
     */
-    
-    private
-    {
-        static QObject __root;
-        QObject __next;
-        QObject __prev;
-    }
-/*    
+
+/*
     override void onSignalHandlerCreated(ref SignalHandler sh)
     {
         sh.signalEvent = &onSignalEvent;
     }
-    
+
     private void onSignalEvent(int signalId, SignalEventId event)
     {
         stringz signature;
-        signalSignature(signalId, signature);        
+        signalSignature(signalId, signature);
         if (signature)
         {
             switch (event)
@@ -107,17 +101,7 @@
         }
     }
 */
-    ~this()
-    {
-        if (__prev)
-            __prev.__next = __next;
-        else
-            __root = __next;
-        
-        if (__next)      
-            __next.__prev = __prev;        
-    }
-    
+
     /**
     */
     T findChild(T : QObject = QObject)(string name = null)
@@ -127,23 +111,23 @@
             auto tmp = cast(T)obj;
             if (tmp && (!name.length || tmp.objectName == name))
                 return tmp;
-            
+
             tmp = obj.findChild!(T)(name);
             if (tmp)
                 return tmp;
         }
-        
+
         return null;
     }
-    
+
     /**
     */
     T[] findChildren(T : QObject = QObject)(string name = null)
     {
         T[] result;
-        
+
         void find(QObject[] objects)
-        {        
+        {
             foreach (obj; objects)
             {
                 auto tmp = cast(T)obj;
@@ -152,11 +136,11 @@
                 find(obj.children);
             }
         }
-        
+
         find(children);
         return result;
     }
-    
+
     static void connect(QObject sender, string signal, QObject receiver, string method, int type = 0)
     {
         QMetaObject.connectImpl(sender, signal, receiver, method, type);
--- a/generator/typesystem_core.xml	Wed Jul 07 22:54:12 2010 +0100
+++ b/generator/typesystem_core.xml	Thu Jul 08 17:20:02 2010 +0300
@@ -1983,12 +1983,12 @@
     </extra-includes>
 
     <inject-code class="native">
-QTD_EXTERN QTD_DLL_PUBLIC int qtd_registerType(char* namePtr, VoidFunc dtor, VoidFunc ctor)
+QTD_EXTERN QTD_DLL_PUBLIC int qtd_QMetaType_registerType(char* namePtr, VoidFunc dtor, VoidFunc ctor)
 {
     return QMetaType::registerType(namePtr, (QMetaType::Destructor)dtor, (QMetaType::Constructor)ctor);
 }
 
-QTD_EXTERN QTD_DLL_PUBLIC void qtd_registerStreamOperators(const char *typeName, VoidFunc saveOp,
+QTD_EXTERN QTD_DLL_PUBLIC void qtd_QMetaType_registerStreamOperators(const char *typeName, VoidFunc saveOp,
                                         VoidFunc loadOp)
 {
     QMetaType::registerStreamOperators(typeName, (QMetaType::SaveOperator)saveOp,
--- a/generator/typesystem_gui-java.java	Wed Jul 07 22:54:12 2010 +0100
+++ b/generator/typesystem_gui-java.java	Thu Jul 08 17:20:02 2010 +0300
@@ -22,7 +22,7 @@
 * exception, Nokia gives you certain additional rights. These rights
 * are described in the Nokia Qt GPL Exception version 1.2, included in
 * the file GPL_EXCEPTION.txt in this package.
-* 
+*
 * Qt for Windows(R) Licensees
 * As a special exception, Nokia, as the sole copyright holder for Qt
 * Designer, grants users of the Qt/Eclipse Integration plug-in the
@@ -170,20 +170,20 @@
 
     @QtBlockedSlot
     public final QPolygon add(int x, int y) {
-        add_private(__nativeId(), x, y);
+        add_private(qtdNativeId(), x, y);
         return this;
     }
 
     @QtBlockedSlot
     public final QPolygon add(QPoint pt) {
-        add_private(__nativeId(), pt.x(), pt.y());
+        add_private(qtdNativeId(), pt.x(), pt.y());
         return this;
     }
 
     @QtBlockedSlot
     public final QPolygon add(QPolygon p) {
         int size = p.size();
-        long nid = __nativeId();
+        long nid = qtdNativeId();
         for (int i = 0; i < size; ++i) {
             QPoint pt = p.at(i);
             add_private(nid, pt.x(), pt.y());
@@ -199,20 +199,20 @@
 
     @QtBlockedSlot
     public final QPolygonF add(double x, double y) {
-        add_private(__nativeId(), x, y);
+        add_private(qtdNativeId(), x, y);
         return this;
     }
 
     @QtBlockedSlot
     public final QPolygonF add(QPointF pt) {
-        add_private(__nativeId(), pt.x(), pt.y());
+        add_private(qtdNativeId(), pt.x(), pt.y());
         return this;
     }
 
     @QtBlockedSlot
     public final QPolygonF add(QPolygonF p) {
         int size = p.size();
-        long nid = __nativeId();
+        long nid = qtdNativeId();
         for (int i = 0; i < size; ++i) {
             QPointF pt = p.at(i);
             add_private(nid, pt.x(), pt.y());
@@ -357,9 +357,9 @@
 		LightGray = new QColor(Qt.GlobalColor.lightGray);
 		Transparent = new QColor(Qt.GlobalColor.transparent);
 		Color0 = new QColor(Qt.GlobalColor.color0);
-		Color1 = new QColor(Qt.GlobalColor.color1);    
+		Color1 = new QColor(Qt.GlobalColor.color1);
 	}
-	
+
     public static const QColor White;
     public static const QColor Black;
     public static const QColor Red;
@@ -482,11 +482,11 @@
     public this(string[] xpm) {
 		this(toStringzArray(xpm));
 	}
-	
+
     public this(string fileName, string format = null, int flags = Qt.ImageConversionFlag.AutoColor) {
         this(fileName, toStringz(format), flags);
     }
-	
+
 /*
         public this(string fileName, string format = null, Qt.ImageConversionFlags flags = Qt.ImageConversionFlag.AutoColor) {
         this(fileName, toStringz(format), flags);
@@ -514,7 +514,7 @@
     public final bool loadFromData(QByteArray data, string format, int flags = Qt.ImageConversionFlag.AutoColor) {
         return loadFromData(data, toStringz(format), flags);
     }
-    
+
 /*	public final bool loadFromData(QByteArray data, string format = null, Qt.ImageConversionFlags flags = Qt.ImageConversionFlag.AutoColor) {
         return loadFromData(data, toStringz(format), flags);
     }
@@ -597,7 +597,7 @@
             __rcUrlHandlers.remove(scheme);
         else
             __rcUrlHandlers[scheme] = receiver;
-    
+
         setUrlHandler(scheme, receiver, "handleUrl");
     }*/
 }// class
@@ -855,21 +855,21 @@
 }// class
 
 class QFileDialog___ extends QFileDialog {
-    
+
     public static string getOpenFileName(QWidget _parent, string caption = null, string dir = null, string filter = null) {
         string res;
         string _selectedFilter = "";
-        qtd_QFileDialog_getOpenFileName_QWidget_string_string_string_nativepointerstring_Options(&res, _parent is null ? null : _parent.__nativeId, caption, dir, filter, _selectedFilter, 0);
+        qtd_QFileDialog_getOpenFileName_QWidget_string_string_string_nativepointerstring_Options(&res, _parent is null ? null : _parent.qtdNativeId, caption, dir, filter, _selectedFilter, 0);
         return res;
     }
-    
+
     public static string getSaveFileName(QWidget _parent, string caption = null, string dir = null, string filter = null) {
         string res;
         string _selectedFilter = "";
-        qtd_QFileDialog_getSaveFileName_QWidget_string_string_string_nativepointerstring_Options(&res, _parent is null ? null : _parent.__nativeId, caption, dir, filter, _selectedFilter, 0);
+        qtd_QFileDialog_getSaveFileName_QWidget_string_string_string_nativepointerstring_Options(&res, _parent is null ? null : _parent.qtdNativeId, caption, dir, filter, _selectedFilter, 0);
         return res;
     }
-    
+
     public static class Filter {
         public this(string filter) {
             this.filter = filter;
@@ -955,7 +955,7 @@
 }// class
 
 class QAction___ extends QAction {
-	
+
         public final void setShortcut(string key) {
 		setShortcut(new QKeySequence(key));
 	}
@@ -1008,53 +1008,53 @@
     public final void setBrush(QPixmap pm) {
         setBrush(new QBrush(pm));
     }
-    
+
     public final void drawConvexPolygon(in QPoint[] points) {
-        qtd_QPainter_drawConvexPolygon_nativepointerQPoint_int(__nativeId, points.ptr, points.length);
+        qtd_QPainter_drawConvexPolygon_nativepointerQPoint_int(qtdNativeId, points.ptr, points.length);
     }
-    
+
     public final void drawConvexPolygon(in QPointF[] points) {
-        qtd_QPainter_drawConvexPolygon_nativepointerQPointF_int(__nativeId, points.ptr, points.length);
+        qtd_QPainter_drawConvexPolygon_nativepointerQPointF_int(qtdNativeId, points.ptr, points.length);
     }
-    
+
     public final void drawLines(in QLine[] lines) {
-        qtd_QPainter_drawLines_nativepointerQLine_int(__nativeId, lines.ptr, lines.length);
+        qtd_QPainter_drawLines_nativepointerQLine_int(qtdNativeId, lines.ptr, lines.length);
     }
 
     public final void drawLines(in QLineF[] lines) {
-        qtd_QPainter_drawLines_nativepointerQLineF_int(__nativeId, lines.ptr, lines.length);
+        qtd_QPainter_drawLines_nativepointerQLineF_int(qtdNativeId, lines.ptr, lines.length);
     }
-    
+
     public final void drawPolygon(in QPoint[] points, Qt.FillRule fillRule = Qt.FillRule.OddEvenFill) {
-        qtd_QPainter_drawPolygon_nativepointerQPoint_int_FillRule(__nativeId, points.ptr, points.length, fillRule);
+        qtd_QPainter_drawPolygon_nativepointerQPoint_int_FillRule(qtdNativeId, points.ptr, points.length, fillRule);
     }
 
     public final void drawPolygon(in QPointF[] points, Qt.FillRule fillRule = Qt.FillRule.OddEvenFill) {
-        qtd_QPainter_drawPolygon_nativepointerQPointF_int_FillRule(__nativeId, points.ptr, points.length, fillRule);
+        qtd_QPainter_drawPolygon_nativepointerQPointF_int_FillRule(qtdNativeId, points.ptr, points.length, fillRule);
     }
 
     public final void drawPolyline(in QPoint[] points) {
-        qtd_QPainter_drawPolyline_nativepointerQPoint_int(__nativeId, points.ptr, points.length);
+        qtd_QPainter_drawPolyline_nativepointerQPoint_int(qtdNativeId, points.ptr, points.length);
     }
 
     public final void drawPolyline(in QPointF[] points) {
-        qtd_QPainter_drawPolyline_nativepointerQPointF_int(__nativeId, points.ptr, points.length);
+        qtd_QPainter_drawPolyline_nativepointerQPointF_int(qtdNativeId, points.ptr, points.length);
     }
-    
+
     public final void drawPoints(in QPoint[] points) {
-        qtd_QPainter_drawPoints_nativepointerQPoint_int(__nativeId, points.ptr, points.length);
+        qtd_QPainter_drawPoints_nativepointerQPoint_int(qtdNativeId, points.ptr, points.length);
     }
 
     public final void drawPoints(in QPointF[] points) {
-        qtd_QPainter_drawPoints_nativepointerQPointF_int(__nativeId, points.ptr, points.length);
+        qtd_QPainter_drawPoints_nativepointerQPointF_int(qtdNativeId, points.ptr, points.length);
     }
-    
+
     public final void drawRects(in QRect[] rects) {
-        qtd_QPainter_drawRects_nativepointerQRect_int(__nativeId, rects.ptr, rects.length);
+        qtd_QPainter_drawRects_nativepointerQRect_int(qtdNativeId, rects.ptr, rects.length);
     }
 
     public final void drawRects(in QRectF[] rects) {
-        qtd_QPainter_drawRects_nativepointerQRectF_int(__nativeId, rects.ptr, rects.length);
+        qtd_QPainter_drawRects_nativepointerQRectF_int(qtdNativeId, rects.ptr, rects.length);
     }
 /*
     public static QPaintDeviceInterface redirected(QPaintDeviceInterface device, qt.core.QPoint offset) {
@@ -1080,14 +1080,14 @@
 	{
 //        if (m_instance != null)
 //            throw new RuntimeException("QCoreApplication can only be initialized once");
-            
+
 		argc = args.length;
 		argv = toStringzArray(args);
 		this(&argc, argv);
 
 //        m_instance.aboutToQuit.connect(m_instance, "disposeOfMyself()");
 	}
-	
+
 	private int argc;
 	private char **argv;
 
@@ -1203,7 +1203,7 @@
      * Gets the widget's window frame margins.
      *
      * @returns An object containing the margins in left, right, top and bottom coordinates.
-     
+
     @QtBlockedSlot
     public final QMarginsF getWindowFrameMargins() {
         QNativePointer left = new QNativePointer(QNativePointer.Type.Double);
@@ -1686,13 +1686,13 @@
 
 class QInputDialog___ extends QInputDialog {
     public static double getDouble(QWidget _parent, string title, string label, double value = 0, double minValue = -2147483647, double maxValue = 2147483647, int decimals = 1, ref bool ok = false, int flags = 0) {
-        return qtd_QInputDialog_getDouble_private_QWidget_string_string_double_double_double_int_nativepointerbool_WindowFlags(_parent is null ? null : _parent.__nativeId, title, label, value, minValue, maxValue, decimals, &ok, flags);
+        return qtd_QInputDialog_getDouble_private_QWidget_string_string_double_double_double_int_nativepointerbool_WindowFlags(_parent is null ? null : _parent.qtdNativeId, title, label, value, minValue, maxValue, decimals, &ok, flags);
     }
-    
+
     static if (QT_VERSION >= QT_VERSION_CHECK(4, 5, 0))
     {
         public static int getInt(QWidget _parent, string title, string label, int value = 0, int minValue = -2147483647, int maxValue = 2147483647, int step = 1, ref bool ok = false, int flags = 0) {
-            return qtd_QInputDialog_getInt_private_QWidget_string_string_int_int_int_int_nativepointerbool_WindowFlags(_parent is null ? null : _parent.__nativeId, title, label, value, minValue, maxValue, step, &ok, flags);
+            return qtd_QInputDialog_getInt_private_QWidget_string_string_int_int_int_int_nativepointerbool_WindowFlags(_parent is null ? null : _parent.qtdNativeId, title, label, value, minValue, maxValue, step, &ok, flags);
     }
     }
 
@@ -1702,16 +1702,16 @@
 
     public static string getText(QWidget _parent, string title, string label, QLineEdit.EchoMode echo = QLineEdit.EchoMode.Normal, string text = null, ref bool ok = false, int flags = 0) {
         string res;
-        qtd_QInputDialog_getText_private_QWidget_string_string_EchoMode_string_nativepointerbool_WindowFlags(&res, _parent is null ? null : _parent.__nativeId, title, label, echo, text, &ok, flags);
+        qtd_QInputDialog_getText_private_QWidget_string_string_EchoMode_string_nativepointerbool_WindowFlags(&res, _parent is null ? null : _parent.qtdNativeId, title, label, echo, text, &ok, flags);
         return res;
     }
 }// class
 
 class QFont___ extends QFont {
-    version(D_Version2) 
+    version(D_Version2)
     {
 	void opAssign(in QFont arg__1)  {
-            this.__nativeId = qtd_QFont_QFont_QFont(arg__1 is null ? null : (cast(QFont)arg__1).__nativeId);
+            this.qtdNativeId = qtd_QFont_QFont_QFont(arg__1 is null ? null : (cast(QFont)arg__1).qtdNativeId);
 	}
     }
 }// class"
--- a/generator/typesystem_gui.xml	Wed Jul 07 22:54:12 2010 +0100
+++ b/generator/typesystem_gui.xml	Thu Jul 08 17:20:02 2010 +0300
@@ -7,7 +7,7 @@
 
 <template name="gui.class_from_variant_java">
     public this(QVariant arg__1) {
-        void* __qt_return_value = qtd_%CLASS_NAME_%CLASS_NAME_QVariant(cast(void*) this, arg__1 is null ? null : arg__1.__nativeId);
+        void* __qt_return_value = qtd_%CLASS_NAME_%CLASS_NAME_QVariant(cast(void*) this, arg__1 is null ? null : arg__1.qtdNativeId);
         super(__qt_return_value);
     }
 </template>
@@ -1138,11 +1138,11 @@
 
     <inject-code class="java">
     public final void insert(int i, QPoint t) {
-        qtd_QPolygon_insert_int_QPoint(__nativeId, i, t);
+        qtd_QPolygon_insert_int_QPoint(qtdNativeId, i, t);
     }
 
     public final void insert(int i, int n, QPoint t) {
-        qtd_QPolygon_insert_int_int_QPoint(__nativeId, i, n, t);
+        qtd_QPolygon_insert_int_int_QPoint(qtdNativeId, i, n, t);
     }
     </inject-code>
     <inject-code class="java-free">
@@ -1223,11 +1223,11 @@
 		-->
     <inject-code class="java">
     public final void insert(int i, QPointF t) {
-        qtd_QPolygonF_insert_int_QPointF(__nativeId, i, t);
+        qtd_QPolygonF_insert_int_QPointF(qtdNativeId, i, t);
     }
 
     public final void insert(int i, int n, QPointF t) {
-        qtd_QPolygonF_insert_int_int_QPointF(__nativeId, i, n, t);
+        qtd_QPolygonF_insert_int_int_QPointF(qtdNativeId, i, n, t);
     }
     </inject-code>
     <inject-code class="java-free">
@@ -5778,7 +5778,7 @@
                 qt.GeneratorUtilities.threadCheck(this);
                 if (nativeId() == 0)
                     throw new QNoNativeResourcesException("Function call on incomplete object of type: " +getClass().getName());
-                __qt_QMessageBox_setWindowModality(__nativeId(), %1.value());
+                __qt_QMessageBox_setWindowModality(qtdNativeId(), %1.value());
                 return ;
             }
             </inject-code>
--- a/mini/test1/build	Wed Jul 07 22:54:12 2010 +0100
+++ b/mini/test1/build	Thu Jul 08 17:20:02 2010 +0300
@@ -1,4 +1,4 @@
 #! /bin/bash
 
-dmd main.d -L-L/home/maxter/qtsdk-2010.02/qt/lib -L-L../../output-linux/build/lib -L-lqtdcore -I../../output-linux/build/ -I../../d2 -L-lQtCore
+dmd main.d -debug -unittest -version=QtdUnittest -L-L/home/maxter/qtsdk-2010.02/qt/lib -L-L../../output-linux/build/lib -L-lqtdcore -I../../output-linux/build/ -I../../d2 -L-lQtCore -L-lcpp_core
 
--- a/mini/test1/build.bat	Wed Jul 07 22:54:12 2010 +0100
+++ b/mini/test1/build.bat	Thu Jul 08 17:20:02 2010 +0300
@@ -1,2 +1,2 @@
 set LIB=E:\d-projects\qtd-trunk\output\build\lib
-dmd main.d -debug -unittest -version=QtdUnittest ..\..\output\build\lib\qtdcore.lib -I../../d2 -I../../output/build
\ No newline at end of file
+dmd main.d -debug -debug=QtdDebug -unittest -version=QtdUnittest ..\..\output\build\lib\qtdcore.lib -I../../d2 -I../../output/build
\ No newline at end of file
--- a/mini/test1/main.d	Wed Jul 07 22:54:12 2010 +0100
+++ b/mini/test1/main.d	Thu Jul 08 17:20:02 2010 +0300
@@ -2,13 +2,12 @@
 
 import std.stdio;
 import std.conv;
-import qtd.QtdObject;
+import qt.core.test.Objects;
 //import qt.gui.QApplication;
 
 void main(string[] args)
 {
     /+
-    writeln("Application");
     scope app = new QApplication(args);
     app.exec();
     +/
--- a/tools/drcc/rcc.cpp	Wed Jul 07 22:54:12 2010 +0100
+++ b/tools/drcc/rcc.cpp	Thu Jul 08 17:20:02 2010 +0300
@@ -733,7 +733,7 @@
 {
     Q_ASSERT(m_errorDevice);
     if (m_format == C_Code)
-        writeString("static const ubyte[] qt_resource_data = [\n");
+        writeString("static immutable ubyte[] qt_resource_data = [\n");
     else if (m_format == Binary)
         m_dataOffset = m_out.size();
     QStack<RCCFileInfo*> pending;
@@ -766,7 +766,7 @@
 bool RCCResourceLibrary::writeDataNames()
 {
     if (m_format == C_Code)
-        writeString("static const ubyte[] qt_resource_name = [\n");
+        writeString("static immutable ubyte[] qt_resource_name = [\n");
     else if (m_format == Binary)
         m_namesOffset = m_out.size();
 
@@ -806,7 +806,7 @@
 bool RCCResourceLibrary::writeDataStructure()
 {
     if (m_format == C_Code)
-        writeString("static const ubyte[] qt_resource_struct = [\n");
+        writeString("static immutable ubyte[] qt_resource_struct = [\n");
     else if (m_format == Binary)
         m_treeOffset = m_out.size();
     QStack<RCCFileInfo*> pending;
@@ -894,8 +894,8 @@
         if (m_useNameSpace)
             writeString("// QT_BEGIN_NAMESPACE\n\n");
         if (m_root) {
-            writeString("extern(C) bool qtd_register_resource_data(int version_, in ubyte *tree, in ubyte *name, in ubyte *data);\n\n");
-            writeString("extern(C) bool qtd_unregister_resource_data(int version_, in ubyte *tree, in ubyte *name, in ubyte *data);\n\n");
+            writeString("extern(C) bool qtd_qRegisterResourceData(int version_, in ubyte *tree, in ubyte *name, in ubyte *data);\n\n");
+            writeString("extern(C) bool qtd_qUnregisterResourceData(int version_, in ubyte *tree, in ubyte *name, in ubyte *data);\n\n");
         }
         if (m_useNameSpace)
             writeString("// QT_END_NAMESPACE\n\n\n");
@@ -907,7 +907,7 @@
 
         if (m_root) {
             writeString("    ");
-            writeString("qtd_register_resource_data(0x01, qt_resource_struct.ptr, "
+            writeString("qtd_qRegisterResourceData(0x01, qt_resource_struct.ptr, "
                        "qt_resource_name.ptr, qt_resource_data.ptr);\n");
         }
         writeString("    return 1;\n");
@@ -921,12 +921,12 @@
         writeString("()\n{\n");
         if (m_root) {
             writeString("    ");
-            writeString("qtd_unregister_resource_data(0x01, qt_resource_struct.ptr, "
+            writeString("qtd_qUnregisterResourceData(0x01, qt_resource_struct.ptr, "
                       "qt_resource_name.ptr, qt_resource_data.ptr);\n");
         }
         writeString("    return 1;\n");
         writeString("}\n\n");
-	
+        
         if(staticInitialize())
         {
             writeString("static this() \n{\n    ");