QSObject QuickInterpreter::wrap( QObject *o )
{
    if( !o ) {
	QSList list;
	return env()->nullClass()->construct( list );
    }

#if defined (QT_THREAD_SUPPORT) && QT_VERSION >= 0x030300
    if (qt_get_application_thread_id() != QThread::currentThread()
	&& o->inherits("QWidget")) {
	qWarning("QuickInterpreter::wrap(), GUI object (%s [%s]) cannot be used in non GUI thread",
		 o->name(), o->className());
	return QSObject();
    }
#endif

    QSUserData *udata = (QSUserData*) o->userData( userDataId() );
    // set user data in QObject if it's not there, yet
    if( !udata ) {
	udata = new QSUserData( 0 );
	o->setUserData( userDataId(), udata );
    }
    QSWrapperShared *shared = udata->data();
    const QSWrapperClass *cl;
    if ( shared ) {
	// wrapper is already there, reuse it
	cl = shared->wrapperClass();
    } else {
	// create & remember wrapper
	cl = new QSWrapperClass( wrapperClass() );
	shared = cl->createShared( o );
	shared->setObjectType( QSWrapperShared::GlobalObject );
	env()->registerShared( shared );
	wrapperShared->append( shared );
    }
    shared->setUserData( udata );
    udata->setData( shared );
    shared->ref(); // additional ref by either QObject or QSObject
    QSObject obj( cl );
    obj.setVal( shared ); // no ownership needs to be transferred anymore
    return obj;
}
Beispiel #2
0
QSObject QuickInterpreter::wrap(QObject *o)
{
    if(!o) {
	QSList list;
	return env()->nullClass()->construct(list);
    }

    if (qsa_is_non_gui_thread() && o->isWidgetType()) {
	qWarning("QuickInterpreter::wrap(), GUI object (%s [%s]) cannot be used in non GUI thread",
		 o->objectName().toLatin1().constData(), o->metaObject()->className());
	return QSObject();
    }

    QSUserData *udata = (QSUserData*) o->userData(userDataId());
    // set user data in QObject if it's not there, yet
    if(!udata) {
	udata = new QSUserData(0);
	o->setUserData(userDataId(), udata);
    }
    QSWrapperShared *shared = udata->data();
    const QSWrapperClass *cl;
    if (shared) {
	// wrapper is already there, reuse it
	cl = shared->wrapperClass();
    } else {
	// create & remember wrapper
	cl = new QSWrapperClass(wrapperClass());
	shared = cl->createShared(o);
	shared->setObjectType(QSWrapperShared::GlobalObject);
	env()->registerShared(shared);
	wrapperShared->append(shared);
    }
    shared->setUserData(udata);
    udata->setData(shared);
    shared->ref(); // additional ref by either QObject or QSObject
    QSObject obj(cl);
    obj.setVal(shared); // no ownership needs to be transferred anymore
    return obj;
}