Qt 4.8
Public Functions | Static Public Variables | Properties | List of all members
QScript::QObjectConnectionManager Class Reference
Inheritance diagram for QScript::QObjectConnectionManager:
QObject

Public Functions

bool addSignalHandler (QObject *sender, int signalIndex, JSC::JSValue receiver, JSC::JSValue slot, JSC::JSValue senderWrapper, Qt::ConnectionType type)
 
void execute (int slotIndex, void **argv)
 
void mark (JSC::MarkStack &)
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
 QObjectConnectionManager (QScriptEnginePrivate *engine)
 
virtual int qt_metacall (QMetaObject::Call, int, void **argv)
 
virtual void * qt_metacast (const char *)
 
bool removeSignalHandler (QObject *sender, int signalIndex, JSC::JSValue receiver, JSC::JSValue slot)
 
 ~QObjectConnectionManager ()
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Static Public Variables

static const QMetaObject staticMetaObject
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 

Properties

QVector< QVector< QObjectConnection > > connections
 
QScriptEnginePrivateengine
 
int slotCounter
 

Additional Inherited Members

- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

Definition at line 122 of file qscriptqobject.cpp.

Constructors and Destructors

◆ QObjectConnectionManager()

QScript::QObjectConnectionManager::QObjectConnectionManager ( QScriptEnginePrivate engine)

Definition at line 2186 of file qscriptqobject.cpp.

2187  : engine(eng), slotCounter(0)
2188 {
2189 }

◆ ~QObjectConnectionManager()

QScript::QObjectConnectionManager::~QObjectConnectionManager ( )

Definition at line 2191 of file qscriptqobject.cpp.

2192 {
2193 }

Functions

◆ addSignalHandler()

bool QScript::QObjectConnectionManager::addSignalHandler ( QObject sender,
int  signalIndex,
JSC::JSValue  receiver,
JSC::JSValue  slot,
JSC::JSValue  senderWrapper,
Qt::ConnectionType  type 
)

Definition at line 2204 of file qscriptqobject.cpp.

Referenced by QScript::QObjectData::addSignalHandler().

2208 {
2209  if (connections.size() <= signalIndex)
2210  connections.resize(signalIndex+1);
2211  QVector<QObjectConnection> &cs = connections[signalIndex];
2212  int absSlotIndex = slotCounter + metaObject()->methodOffset();
2213  bool ok = QMetaObject::connect(sender, signalIndex, this, absSlotIndex, type);
2214  if (ok) {
2215  cs.append(QObjectConnection(slotCounter++, receiver, function, senderWrapper));
2216  QMetaMethod signal = sender->metaObject()->method(signalIndex);
2217  QByteArray signalString;
2218  signalString.append('2'); // signal code
2219  signalString.append(signal.signature());
2220  static_cast<QObjectNotifyCaller*>(sender)->callConnectNotify(signalString);
2221  }
2222  return ok;
2223 }
static bool connect(const QObject *sender, int signal_index, const QObject *receiver, int method_index, int type=0, int *types=0)
Definition: qobject.cpp:3194
QByteArray & append(char c)
Appends the character ch to this byte array.
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.
QObject * sender() const
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; othe...
Definition: qobject.cpp:2327
QVector< QVector< QObjectConnection > > connections
int methodOffset() const
Returns the method offset for this class; i.e.
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
static Type type(const QScriptValue &v)
QMetaMethod method(int index) const
Returns the meta-data for the method with the given index.
const char * signature() const
Returns the signature of this method (e.g., setValue(double)).
The QMetaMethod class provides meta-data about a member function.
Definition: qmetaobject.h:56
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.

◆ execute()

void QScript::QObjectConnectionManager::execute ( int  slotIndex,
void **  argv 
)

Definition at line 2081 of file qscriptqobject.cpp.

2082 {
2083  JSC::JSValue receiver;
2084  JSC::JSValue slot;
2085  JSC::JSValue senderWrapper;
2086  int signalIndex = -1;
2087  QScript::APIShim shim(engine);
2088  for (int i = 0; i < connections.size(); ++i) {
2089  const QVector<QObjectConnection> &cs = connections.at(i);
2090  for (int j = 0; j < cs.size(); ++j) {
2091  const QObjectConnection &c = cs.at(j);
2092  if (c.slotIndex == slotIndex) {
2093  receiver = c.receiver;
2094  slot = c.slot;
2095  senderWrapper = c.senderWrapper;
2096  signalIndex = i;
2097  break;
2098  }
2099  }
2100  }
2101  if (!slot) {
2102  // This connection no longer exists (can happen if the signal is
2103  // emitted from another thread and the call gets queued, but the
2104  // connection is removed before the QMetaCallEvent gets processed).
2105  return;
2106  }
2107  Q_ASSERT(slot.isObject());
2108 
2109  if (engine->isCollecting()) {
2110  qWarning("QtScript: can't execute signal handler during GC");
2111  // we can't do a script function call during GC,
2112  // so we're forced to ignore this signal
2113  return;
2114  }
2115 
2116 #if 0
2117  QScriptFunction *fun = engine->convertToNativeFunction(slot);
2118  if (fun == 0) {
2119  // the signal handler has been GC'ed. This can only happen when
2120  // a QObject is owned by the engine, the engine is destroyed, and
2121  // there is a script function connected to the destroyed() signal
2122  Q_ASSERT(signalIndex <= 1); // destroyed(QObject*)
2123  return;
2124  }
2125 #endif
2126 
2127  const QMetaObject *meta = sender()->metaObject();
2128  const QMetaMethod method = meta->method(signalIndex);
2129 
2130  QList<QByteArray> parameterTypes = method.parameterTypes();
2131  int argc = parameterTypes.count();
2132 
2133  JSC::ExecState *exec = engine->currentFrame;
2134  QVarLengthArray<JSC::JSValue, 8> argsVector(argc);
2135  for (int i = 0; i < argc; ++i) {
2136  JSC::JSValue actual;
2137  void *arg = argv[i + 1];
2138  QByteArray typeName = parameterTypes.at(i);
2139  int argType = QMetaType::type(parameterTypes.at(i));
2140  if (!argType) {
2141  qWarning("QScriptEngine: Unable to handle unregistered datatype '%s' "
2142  "when invoking handler of signal %s::%s",
2143  typeName.constData(), meta->className(), method.signature());
2144  actual = JSC::jsUndefined();
2145  } else if (argType == QMetaType::QVariant) {
2146  actual = QScriptEnginePrivate::jscValueFromVariant(exec, *reinterpret_cast<QVariant*>(arg));
2147  } else {
2148  actual = QScriptEnginePrivate::create(exec, argType, arg);
2149  }
2150  argsVector[i] = actual;
2151  }
2152  JSC::ArgList jscArgs(argsVector.data(), argsVector.size());
2153 
2154  JSC::JSValue senderObject;
2155  if (senderWrapper && senderWrapper.inherits(&QScriptObject::info)) // ### check if it's actually a QObject wrapper
2156  senderObject = senderWrapper;
2157  else {
2158  QScriptEngine::QObjectWrapOptions opt = QScriptEngine::PreferExistingWrapperObject;
2159  senderObject = engine->newQObject(sender(), QScriptEngine::QtOwnership, opt);
2160  }
2161 
2162  JSC::JSValue thisObject;
2163  if (receiver && receiver.isObject())
2164  thisObject = receiver;
2165  else
2166  thisObject = engine->globalObject();
2167 
2168  JSC::CallData callData;
2169  JSC::CallType callType = slot.getCallData(callData);
2170  if (exec->hadException())
2171  exec->clearException(); // ### otherwise JSC asserts
2172  JSC::call(exec, slot, callType, callData, thisObject, jscArgs);
2173 
2174  if (exec->hadException()) {
2175  if (slot.inherits(&QtFunction::info) && !static_cast<QtFunction*>(JSC::asObject(slot))->qobject()) {
2176  // The function threw an error because the target QObject has been deleted.
2177  // The connections list is stale; remove the signal handler and ignore the exception.
2178  removeSignalHandler(sender(), signalIndex, receiver, slot);
2179  exec->clearException();
2180  } else {
2182  }
2183  }
2184 }
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
unsigned char c[8]
Definition: qnumeric_p.h:62
bool removeSignalHandler(QObject *sender, int signalIndex, JSC::JSValue receiver, JSC::JSValue slot)
static JSC::JSValue jscValueFromVariant(JSC::ExecState *, const QVariant &value)
static JSC::JSValue create(JSC::ExecState *, int type, const void *ptr)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
JSC::JSObject * globalObject() const
static const JSC::ClassInfo info
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
JSC::ExecState * currentFrame
QObject * sender() const
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; othe...
Definition: qobject.cpp:2327
QVector< QVector< QObjectConnection > > connections
const char * typeName
Definition: qmetatype.cpp:239
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
Q_CORE_EXPORT void qWarning(const char *,...)
static int type(const char *typeName)
Returns a handle to the type called typeName, or 0 if there is no such type.
Definition: qmetatype.cpp:607
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
QList< QByteArray > parameterTypes() const
Returns a list of parameter types.
const char * className() const
Returns the class name.
Definition: qobjectdefs.h:491
JSC::JSValue newQObject(QObject *object, QScriptEngine::ValueOwnership ownership=QScriptEngine::QtOwnership, const QScriptEngine::QObjectWrapOptions &options=0)
QMetaMethod method(int index) const
Returns the meta-data for the method with the given index.
const char * signature() const
Returns the signature of this method (e.g., setValue(double)).
static const JSC::ClassInfo info
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
The QMetaMethod class provides meta-data about a member function.
Definition: qmetaobject.h:56
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.

◆ mark()

void QScript::QObjectConnectionManager::mark ( JSC::MarkStack &  markStack)

Definition at line 2195 of file qscriptqobject.cpp.

Referenced by QScript::QObjectData::mark().

2196 {
2197  for (int i = 0; i < connections.size(); ++i) {
2199  for (int j = 0; j < cs.size(); ++j)
2200  cs[j].mark(markStack);
2201  }
2202 }
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
QVector< QVector< QObjectConnection > > connections
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ metaObject()

const QMetaObject * QScript::QObjectConnectionManager::metaObject ( ) const
virtual

Returns a pointer to the meta-object of this object.

A meta-object contains information about a class that inherits QObject, e.g. class name, superclass name, properties, signals and slots. Every QObject subclass that contains the Q_OBJECT macro will have a meta-object.

The meta-object information is required by the signal/slot connection mechanism and the property system. The inherits() function also makes use of the meta-object.

If you have no pointer to an actual object instance but still want to access the meta-object of a class, you can use staticMetaObject .

Example:

QObject *obj = new QPushButton;
obj->metaObject()->className(); // returns "QPushButton"
QPushButton::staticMetaObject.className(); // returns "QPushButton"
See also
staticMetaObject

Reimplemented from QObject.

Definition at line 2056 of file qscriptqobject.cpp.

Referenced by addSignalHandler(), and removeSignalHandler().

2057 {
2058  return &staticMetaObject;
2059 }
static const QMetaObject staticMetaObject

◆ qt_metacall()

int QScript::QObjectConnectionManager::qt_metacall ( QMetaObject::Call  _c,
int  _id,
void **  argv 
)
virtual

Definition at line 2069 of file qscriptqobject.cpp.

2070 {
2071  _id = QObject::qt_metacall(_c, _id, _a);
2072  if (_id < 0)
2073  return _id;
2074  if (_c == QMetaObject::InvokeMetaMethod) {
2075  execute(_id, _a);
2076  _id -= slotCounter;
2077  }
2078  return _id;
2079 }
void execute(int slotIndex, void **argv)

◆ qt_metacast()

void * QScript::QObjectConnectionManager::qt_metacast ( const char *  _clname)
virtual

Definition at line 2061 of file qscriptqobject.cpp.

2062 {
2063  if (!_clname) return 0;
2064  if (!strcmp(_clname, qt_meta_stringdata_QObjectConnectionManager))
2065  return static_cast<void*>(const_cast<QObjectConnectionManager*>(this));
2066  return QObject::qt_metacast(_clname);
2067 }
static const char qt_meta_stringdata_QObjectConnectionManager[]
QObjectConnectionManager(QScriptEnginePrivate *engine)

◆ removeSignalHandler()

bool QScript::QObjectConnectionManager::removeSignalHandler ( QObject sender,
int  signalIndex,
JSC::JSValue  receiver,
JSC::JSValue  slot 
)

Definition at line 2225 of file qscriptqobject.cpp.

Referenced by QScript::QObjectData::removeSignalHandler().

2228 {
2229  if (connections.size() <= signalIndex)
2230  return false;
2231  QVector<QObjectConnection> &cs = connections[signalIndex];
2232  for (int i = 0; i < cs.size(); ++i) {
2233  const QObjectConnection &c = cs.at(i);
2234  if (c.hasTarget(receiver, slot)) {
2235  int absSlotIndex = c.slotIndex + metaObject()->methodOffset();
2236  bool ok = QMetaObject::disconnect(sender, signalIndex, this, absSlotIndex);
2237  if (ok) {
2238  cs.remove(i);
2239  QMetaMethod signal = sender->metaObject()->method(signalIndex);
2240  QByteArray signalString;
2241  signalString.append('2'); // signal code
2242  signalString.append(signal.signature());
2243  static_cast<QScript::QObjectNotifyCaller*>(sender)->callDisconnectNotify(signalString);
2244  }
2245  return ok;
2246  }
2247  }
2248  return false;
2249 }
unsigned char c[8]
Definition: qnumeric_p.h:62
void remove(int i)
Removes the element at index position i.
Definition: qvector.h:374
QByteArray & append(char c)
Appends the character ch to this byte array.
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.
QObject * sender() const
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; othe...
Definition: qobject.cpp:2327
QVector< QVector< QObjectConnection > > connections
int methodOffset() const
Returns the method offset for this class; i.e.
static bool disconnect(const QObject *sender, int signal_index, const QObject *receiver, int method_index)
Definition: qobject.cpp:3276
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
QMetaMethod method(int index) const
Returns the meta-data for the method with the given index.
const char * signature() const
Returns the signature of this method (e.g., setValue(double)).
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
The QMetaMethod class provides meta-data about a member function.
Definition: qmetaobject.h:56
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.

Properties

◆ connections

QVector<QVector<QObjectConnection> > QScript::QObjectConnectionManager::connections
private

Definition at line 149 of file qscriptqobject.cpp.

Referenced by addSignalHandler(), mark(), and removeSignalHandler().

◆ engine

QScriptEnginePrivate* QScript::QObjectConnectionManager::engine
private

Definition at line 147 of file qscriptqobject.cpp.

◆ slotCounter

int QScript::QObjectConnectionManager::slotCounter
private

Definition at line 148 of file qscriptqobject.cpp.

Referenced by addSignalHandler().

◆ staticMetaObject

const QMetaObject QScript::QObjectConnectionManager::staticMetaObject
static

The documentation for this class was generated from the following file: