Logo Search packages:      
Sourcecode: qtjambi version File versions  Download package

static QtJambiObject com::trolltech::qt::QtJambiObject::reassignNativeResources ( QtJambiObject  object,
Class<?extends QtJambiObject clazz 
) throws InstantiationException [inline, static, inherited]

In certain, uncommon cases, the native resources of a QtJambiObject object may be out of sync with its class. In such cases this method can be used to reassign the native resources to an object of another class. Take special care when using this method, as it has limited type safety and may cause crashes when used in the wrong way. Note also that as the returned object "steals" the native resources held by the original object, the original object will not be usable after a call to this function. Invoking a method on the original object may result in an exception being raised. If an exception is raised, it is safe to assume that the original object is still valid. If the object is already of the type specified by clazz, then a reference to the object itself is returned.

object The original object which holds the native resources. This object will be considered unusable after the call.
clazz The class of the new object. The class must be a subclass of QtJambiObject and you must not rely on any constructors being invoked upon construction of the object.
An object of the specified type which owns the resources previously held by object.
ClassCastException If the class of object is unrelated to clazz, or if clazz is an unsupported class type.
InstantiationException If clazz cannot be instantiated

Definition at line 210 of file QtJambiObject.java.

References com::trolltech::qt::QtJambiObject::nativeId().

        if (!object.getClass().isAssignableFrom(clazz)) {
            throw new ClassCastException("The object '" + object.toString() + "' (class: '" + object.getClass().getName() + "') " 
                                         + "must be of class '" + clazz.getName() + "' or one of its superclasses.");

        if (object.getClass().equals(clazz))
            return object;

        if (object.native__id == 0)
            throw new QNoNativeResourcesException("The object '" + object.toString() + "' does not have native resources.");

        Constructor<? extends QtJambiObject> c;
        try {
            c = clazz.getDeclaredConstructor(QPrivateConstructor.class);
        } catch (NoSuchMethodException e) {
            ClassCastException new_e = new ClassCastException("The class '" + clazz.getName() + "' must be of a generated type.");
            throw new_e;

        long nativeId = object.native__id;
        object.native__id = 0;
        return __qt_reassignLink(nativeId, clazz, c);

Generated by  Doxygen 1.6.0   Back to index