error *objectConnect(QObject_ *object, const char *signal, int signalLen, QQmlEngine_ *engine, void *func, int argsLen) { QObject *qobject = reinterpret_cast<QObject *>(object); QQmlEngine *qengine = reinterpret_cast<QQmlEngine *>(engine); QByteArray qsignal(signal, signalLen); const QMetaObject *meta = qobject->metaObject(); // Walk backwards so descendants have priority. for (int i = meta->methodCount()-1; i >= 0; i--) { QMetaMethod method = meta->method(i); if (method.methodType() == QMetaMethod::Signal) { QByteArray name = method.name(); if (name.length() == signalLen && qstrncmp(name.constData(), signal, signalLen) == 0) { if (method.parameterCount() < argsLen) { // TODO Might continue looking to see if a different signal has the same name and enough arguments. return errorf("signal \"%s\" has too few parameters for provided function", name.constData()); } Connector *connector = new Connector(qobject, method, qengine, func, argsLen); const QMetaObject *connmeta = connector->metaObject(); QObject::connect(qobject, method, connector, connmeta->method(connmeta->methodOffset())); return 0; } } } // Cannot use constData here as the byte array is not null-terminated. return errorf("object does not expose a \"%s\" signal", qsignal.data()); }
/*! Returns the value of the \a name property for this context as a QVariant. */ QVariant QQmlContext::contextProperty(const QString &name) const { Q_D(const QQmlContext); QVariant value; int idx = -1; QQmlContextData *data = d->data; const QV4::IdentifierHash<int> &properties = data->propertyNames(); if (properties.count()) idx = properties.value(name); if (idx == -1) { if (data->contextObject) { QObject *obj = data->contextObject; QQmlPropertyData local; QQmlPropertyData *property = QQmlPropertyCache::property(data->engine, obj, name, data, local); if (property) value = obj->metaObject()->property(property->coreIndex()).read(obj); } if (!value.isValid() && parentContext()) value = parentContext()->contextProperty(name); } else { if (idx >= d->propertyValues.count()) value = QVariant::fromValue(data->idValues[idx - d->propertyValues.count()].data()); else value = d->propertyValues[idx]; } return value; }
/*! Returns the value of the \a name property for this context as a QVariant. */ QVariant QDeclarativeContext::contextProperty(const QString &name) const { Q_D(const QDeclarativeContext); QVariant value; int idx = -1; QDeclarativeContextData *data = d->data; if (data->propertyNames) idx = data->propertyNames->value(name); if (idx == -1) { QByteArray utf8Name = name.toUtf8(); if (data->contextObject) { QObject *obj = data->contextObject; QDeclarativePropertyCache::Data local; QDeclarativePropertyCache::Data *property = QDeclarativePropertyCache::property(data->engine, obj, name, local); if (property) value = obj->metaObject()->property(property->coreIndex).read(obj); } if (!value.isValid() && parentContext()) value = parentContext()->contextProperty(name); } else { if (idx >= d->propertyValues.count()) value = QVariant::fromValue(data->idValues[idx - d->propertyValues.count()].data()); else value = d->propertyValues[idx]; } return value; }
int SignalProxy::SignalRelay::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QObject::qt_metacall(_c, _id, _a); if(_id < 0) return _id; if(_c == QMetaObject::InvokeMetaMethod) { if(_slots.contains(_id)) { QObject *caller = sender(); SignalProxy::ExtendedMetaObject *eMeta = proxy()->extendedMetaObject(caller->metaObject()); Q_ASSERT(eMeta); const Signal &signal = _slots[_id]; QVariantList params; params << signal.signature; const QList<int> &argTypes = eMeta->argTypes(signal.signalId); for(int i = 0; i < argTypes.size(); i++) { if(argTypes[i] == 0) { qWarning() << "SignalRelay::qt_metacall(): received invalid data for argument number" << i << "of signal" << QString("%1::%2").arg(caller->metaObject()->className()).arg(caller->metaObject()->method(_id).signature()); qWarning() << " - make sure all your data types are known by the Qt MetaSystem"; return _id; } params << QVariant(argTypes[i], _a[i+1]); } proxy()->dispatchSignal(SignalProxy::RpcCall, params); } _id -= _slots.count(); } return _id; }
void BibleTime::slotDebugTimeout() { QMutexLocker lock(&m_debugWindowLock); if (m_debugWindow == 0 || m_debugWindow->isVisible() == false) return; QTimer::singleShot(0, this, SLOT(slotDebugTimeout())); QObject *w = QApplication::widgetAt(QCursor::pos()); if (w != 0) { QString objectHierarchy; do { const QMetaObject *m = w->metaObject(); QString classHierarchy; do { if (!classHierarchy.isEmpty()) classHierarchy += ": "; classHierarchy += m->className(); m = m->superClass(); } while (m != 0); if (!objectHierarchy.isEmpty()) { objectHierarchy += "<br/><b>child of:</b> "; } else { objectHierarchy += "<b>This widget is:</b> "; } objectHierarchy += classHierarchy; w = w->parent(); } while (w != 0); m_debugWindow->setText(objectHierarchy); } else { m_debugWindow->setText("No widget"); } m_debugWindow->resize(m_debugWindow->minimumSizeHint()); }
ParamEnum::ParamEnum( QObject *parent, const char* name, int value, const QString& e, int *ptr ) : AbstractParam(parent, name, QVariant::Int) { m_ptr = ptr; QStringList L = e.split('|', QString::SkipEmptyParts); if (!L.isEmpty()) { for (int i = 0; i < L.size(); ++i) { m_keys.append(L[i]); m_values.append(i); } } else { QObject *p = parent; while (p) { const QMetaObject *mo = p->metaObject(); int index = mo->indexOfEnumerator(e.toLatin1().data()); if (index >= 0) { const QMetaEnum me = mo->enumerator(index); for (int i = 0; i < me.keyCount(); ++i) { m_keys.append(me.key(i)); m_values.append(me.value(i)); } break; } p = p->parent(); } } m_value = m_defaultValue = value; if (m_ptr) *m_ptr = m_value; }
void collectReachableMetaObjects(QObject *object, QSet<const QMetaObject *> *metas) { if (! object) return; const QMetaObject *meta = object->metaObject(); if (verbose) qDebug() << "Processing object" << meta->className(); collectReachableMetaObjects(meta, metas); for (int index = 0; index < meta->propertyCount(); ++index) { QMetaProperty prop = meta->property(index); if (QQmlMetaType::isQObject(prop.userType())) { if (verbose) qDebug() << " Processing property" << prop.name(); currentProperty = QString("%1::%2").arg(meta->className(), prop.name()); // if the property was not initialized during construction, // accessing a member of oo is going to cause a segmentation fault QObject *oo = QQmlMetaType::toQObject(prop.read(object)); if (oo && !metas->contains(oo->metaObject())) collectReachableMetaObjects(oo, metas); currentProperty.clear(); } } }
void QtInstance::getPropertyNames(ExecState* exec, PropertyNameArray& array) { // This is the enumerable properties, so put: // properties // dynamic properties // slots QObject* obj = getObject(); if (obj) { const QMetaObject* meta = obj->metaObject(); int i; for (i = 0; i < meta->propertyCount(); i++) { QMetaProperty prop = meta->property(i); if (prop.isScriptable()) array.add(Identifier(exec, prop.name())); } #ifndef QT_NO_PROPERTIES QList<QByteArray> dynProps = obj->dynamicPropertyNames(); foreach (const QByteArray& ba, dynProps) array.add(Identifier(exec, ba.constData())); #endif const int methodCount = meta->methodCount(); for (i = 0; i < methodCount; i++) { QMetaMethod method = meta->method(i); if (method.access() != QMetaMethod::Private) array.add(Identifier(exec, method.signature())); } } }
QStringList QDeclarativeObjectScriptClass::propertyNames(Object *object) { QObject *obj = toQObject(object); if (!obj) return QStringList(); QDeclarativeEnginePrivate *enginePrivate = QDeclarativeEnginePrivate::get(engine); QDeclarativePropertyCache *cache = 0; QDeclarativeData *ddata = QDeclarativeData::get(obj); if (ddata) cache = ddata->propertyCache; if (!cache) { cache = enginePrivate->cache(obj); if (cache) { if (ddata) { cache->addref(); ddata->propertyCache = cache; } } else { // Not cachable - fall back to QMetaObject (eg. dynamic meta object) // XXX QDeclarativeOpenMetaObject has a cache, so this is suboptimal. // XXX This is a workaround for QTBUG-9420. const QMetaObject *mo = obj->metaObject(); QStringList r; int pc = mo->propertyCount(); int po = mo->propertyOffset(); for (int i=po; i<pc; ++i) r += QString::fromUtf8(mo->property(i).name()); return r; } } return cache->propertyNames(); }
bool QtOnChangeWithKeepAliveSubscriptionQos::equals(const QObject& other) const { int typeThis = QMetaType::type(this->metaObject()->className()); int typeOther = QMetaType::type(other.metaObject()->className()); auto newOther = dynamic_cast<const QtOnChangeWithKeepAliveSubscriptionQos*>(&other); return typeThis == typeOther && *this == *newOther; }
void SignalTransition::connectTriggered() { if (!m_complete || !m_cdata) return; QObject *target = senderObject(); QQmlData *ddata = QQmlData::get(this); QQmlContextData *ctxtdata = ddata ? ddata->outerContext : 0; Q_ASSERT(m_bindings.count() == 1); const QV4::CompiledData::Binding *binding = m_bindings.at(0); Q_ASSERT(binding->type == QV4::CompiledData::Binding::Type_Script); QV4::ExecutionEngine *jsEngine = QV8Engine::getV4(QQmlEngine::contextForObject(this)->engine()); QV4::Scope scope(jsEngine); QV4::Scoped<QV4::QObjectMethod> qobjectSignal(scope, QJSValuePrivate::convertedToValue(jsEngine, m_signal)); Q_ASSERT(qobjectSignal); QMetaMethod metaMethod = target->metaObject()->method(qobjectSignal->methodIndex()); int signalIndex = QMetaObjectPrivate::signalIndex(metaMethod); QQmlBoundSignalExpression *expression = ctxtdata ? new QQmlBoundSignalExpression(target, signalIndex, ctxtdata, this, m_cdata->compilationUnit->runtimeFunctions[binding->value.compiledScriptIndex]) : 0; if (expression) expression->setNotifyOnValueChanged(false); m_signalExpression = expression; }
StyleSet::StyleSet(QObject* pParent) : QObject(pParent) , mpStyleSetProps(StyleSetProps::nullStyleSetProps()) { auto* pEngine = StyleEngineHost::globalStyleEngine(); QObject* p = parent(); if (p) { QQuickItem* pItem = qobject_cast<QQuickItem*>(p); if (pItem != nullptr) { connect(pItem, &QQuickItem::parentChanged, this, &StyleSet::onParentChanged); } else if (p->parent() != nullptr) { styleSheetsLogInfo() << "Parent to StyleSet is not a QQuickItem but '" << p->metaObject()->className() << "'. " << "Hierarchy changes for this component won't be detected."; if (pEngine) { Q_EMIT pEngine->exception( QString::fromLatin1("noParentChangeReports"), QString::fromLatin1("Hierarchy changes for this component won't be detected")); } } mPath = traversePathUp(p); if (!pEngine) { connect(StyleEngineHost::globalStyleEngineHost(), &StyleEngineHost::styleEngineLoaded, this, &StyleSet::onStyleEngineLoaded); } setupStyle(); } }
static int lqtL_connect(lua_State *L) { static int methodId = 0; QObject* sender = static_cast<QObject*>(lqtL_toudata(L, 1, "QObject*")); if (sender == NULL) return luaL_argerror(L, 1, "sender not QObject*"); const char *signal = luaL_checkstring(L, 2); const QMetaObject *senderMeta = sender->metaObject(); int idxS = senderMeta->indexOfSignal(signal + 1); if (idxS == -1) return luaL_argerror(L, 2, qPrintable(QString("no such sender signal: '%1'").arg(signal + 1))); QObject* receiver; QString methodName; if (lua_type(L, 3) == LUA_TFUNCTION) { receiver = sender; // simulate sender:__addmethod('LQT_SLOT_X(signature)', function()...end) QMetaMethod m = senderMeta->method(idxS); methodName = QString(m.signature()).replace(QRegExp("^[^\\(]+"), QString("LQT_SLOT_%1").arg(methodId++)); lua_getfield(L, 1, "__addmethod"); lua_pushvalue(L, 1); lua_pushstring(L, qPrintable(methodName)); lua_pushvalue(L, 3); lua_call(L, 3, 0); methodName.prepend("1"); } else { receiver = static_cast<QObject*>(lqtL_toudata(L, 3, "QObject*")); if (receiver == NULL) return luaL_argerror(L, 3, "receiver not QObject*"); const char *method = luaL_checkstring(L, 4); methodName = method; const QMetaObject *receiverMeta = receiver->metaObject(); int idxR = receiverMeta->indexOfMethod(method + 1); if (idxR == -1) return luaL_argerror(L, 4, qPrintable(QString("no such receiver method: '%1'").arg(method + 1))); } bool ok = QObject::connect(sender, signal, receiver, qPrintable(methodName)); lua_pushboolean(L, ok); return 1; }
JSValue QtInstance::stringValue(ExecState* exec) const { QObject* obj = getObject(); if (!obj) return jsNull(); // Hmm.. see if there is a toString defined QByteArray buf; bool useDefault = true; getClass(); if (m_class) { // Cheat and don't use the full name resolution int index = obj->metaObject()->indexOfMethod("toString()"); if (index >= 0) { QMetaMethod m = obj->metaObject()->method(index); // Check to see how much we can call it if (m.access() != QMetaMethod::Private && m.methodType() != QMetaMethod::Signal && m.parameterTypes().isEmpty()) { const char* retsig = m.typeName(); if (retsig && *retsig) { QVariant ret(QMetaType::type(retsig), (void*)0); void * qargs[1]; qargs[0] = ret.data(); if (QMetaObject::metacall(obj, QMetaObject::InvokeMetaMethod, index, qargs) < 0) { if (ret.isValid() && ret.canConvert(QVariant::String)) { buf = ret.toString().toLatin1().constData(); // ### Latin 1? Ascii? useDefault = false; } } } } } } if (useDefault) { const QMetaObject* meta = obj ? obj->metaObject() : &QObject::staticMetaObject; QString name = obj ? obj->objectName() : QString::fromUtf8("unnamed"); QString str = QString::fromUtf8("%0(name = \"%1\")") .arg(QLatin1String(meta->className())).arg(name); buf = str.toLatin1(); } return jsString(exec, buf.constData()); }
void mafObjectFactoryTest::instantiateQObjectFromStringTest() { mafRegisterQtObject(QObject); QObject *obj = mafNEWQtFromString("QObject"); QVERIFY(obj != NULL); QString cn = obj->metaObject()->className(); QVERIFY(cn == "QObject"); delete obj; }
// Connect up a particular slot name, with optional arguments. static void connect(QObject *qobj, PyObject *slot_obj, const QByteArray &slot_nm, const QByteArray &args) { // Ignore if it's not an autoconnect slot. if (!slot_nm.startsWith("on_")) return; // Extract the names of the emitting object and the signal. int i; i = slot_nm.lastIndexOf('_'); if (i - 3 < 1 || i + 1 >= slot_nm.size()) return; QByteArray ename = slot_nm.mid(3, i - 3); QByteArray sname = slot_nm.mid(i + 1); // Find the emitting object and get its meta-object. QObject *eobj = qobj->findChild<QObject *>(ename); if (!eobj) return; const QMetaObject *mo = eobj->metaObject(); // Got through the methods looking for a matching signal. for (int m = 0; m < mo->methodCount(); ++m) { QMetaMethod mm = mo->method(m); if (mm.methodType() != QMetaMethod::Signal) continue; QByteArray sig(mm.methodSignature()); if (Chimera::Signature::name(sig) != sname) continue; // If we have slot arguments then they must match as well. if (!args.isEmpty() && Chimera::Signature::arguments(sig) != args) continue; QObject *receiver; QByteArray slot_sig; if (pyqt5_get_connection_parts(slot_obj, eobj, sig.constData(), false, &receiver, slot_sig) != sipErrorNone) continue; // Add the type character. sig.prepend('2'); // Connect the signal. QObject::connect(eobj, sig.constData(), receiver, slot_sig.constData()); } }
void Tools::printChildren(QObject* parent) { const QObjectList objs = parent->children(); QObject * obj; for (int i = 0 ; i < objs.size() ; i++) { obj = objs.at(i); kDebug() << k_funcinfo << obj->metaObject()->className() << ": " << obj->objectName() << endl; } }
int QQmlProxyMetaObject::metaCall(QObject *o, QMetaObject::Call c, int id, void **a) { Q_ASSERT(object == o); if ((c == QMetaObject::ReadProperty || c == QMetaObject::WriteProperty) && id >= metaObjects->constLast().propertyOffset) { for (int ii = 0; ii < metaObjects->count(); ++ii) { const ProxyData &data = metaObjects->at(ii); if (id >= data.propertyOffset) { if (!proxies) { proxies = new QObject*[metaObjects->count()]; ::memset(proxies, 0, sizeof(QObject *) * metaObjects->count()); } if (!proxies[ii]) { QObject *proxy = data.createFunc(object); const QMetaObject *metaObject = proxy->metaObject(); proxies[ii] = proxy; int localOffset = data.metaObject->methodOffset(); int methodOffset = metaObject->methodOffset(); int methods = metaObject->methodCount() - methodOffset; // ### - Can this be done more optimally? for (int jj = 0; jj < methods; ++jj) { QMetaMethod method = metaObject->method(jj + methodOffset); if (method.methodType() == QMetaMethod::Signal) QQmlPropertyPrivate::connect(proxy, methodOffset + jj, object, localOffset + jj); } } int proxyOffset = proxies[ii]->metaObject()->propertyOffset(); int proxyId = id - data.propertyOffset + proxyOffset; return proxies[ii]->qt_metacall(c, proxyId, a); } } } else if (c == QMetaObject::InvokeMetaMethod && id >= metaObjects->constLast().methodOffset) { QMetaMethod m = object->metaObject()->method(id); if (m.methodType() == QMetaMethod::Signal) { QMetaObject::activate(object, id, a); return -1; } } if (parent) return parent->metaCall(o, c, id, a); else return object->qt_metacall(c, id, a); }
static QScriptValue qtscript_dir(QScriptContext *ctx, QScriptEngine *eng) { QObject *obj = ctx->argument(0).toQObject(); if (obj) { const QMetaObject* meta = obj->metaObject(); for(int i = meta->propertyOffset(); i < meta->propertyCount(); ++i) qDebug() << meta->property(i).name(); } return eng->undefinedValue(); }
extern "C" SEXP qt_qmetaInvoke(SEXP x, SEXP s_id, SEXP s_args) { SmokeObject *so = SmokeObject::fromSexp(x); int id = from_sexp<int>(s_id); QObject * qobj = reinterpret_cast<QObject *>(so->castPtr("QObject")); MocMethod method(so->smoke(), qobj->metaObject(), id); SEXP ret = method.invoke(x, s_args); if (method.lastError() > Method::NoError) error("Meta method invocation failed for: '%s::%s'", so->klass()->name(), method.name()); return ret; }
void CDiagramItem::fromXml(const QDomElement &n) { QDomElement e; QString type, name, prop; QObject *obj = NULL; QMetaProperty pro; QMetaObject *meta = NULL; CDiagramSerializable *serialItem = NULL; setLibraryCategory(n.attribute( QString("libCategory") ) ); setLibraryName(n.attribute( QString("libName") ) ); setCategory(n.attribute( QString("category") ) ); setName(n.attribute( QString("name") ) ); setId(n.attribute( QString("id") ).toInt() ); obj = dynamic_cast<QObject*>(this); e = n.firstChildElement( QString("property") ); while (!e.isNull()) { QByteArray b; name = e.attribute( QString("name") ); type = e.attribute( QString("type") ); b = QByteArray::fromBase64( e.text().toAscii() ); QDataStream s(&b, QIODevice::ReadOnly); QVariant value(s); if (value.convert( QVariant::nameToType( qPrintable(type) ) ) ) { meta = const_cast<QMetaObject*>( obj->metaObject() ); pro = meta->property( meta->indexOfProperty(qPrintable(name)) ); if (pro.isWritable()) obj->setProperty(qPrintable(name), value); } e = e.nextSiblingElement( QString("property") ); } e = n.firstChildElement( QString("children") ); if (!e.isNull()) { e = e.firstChildElement( QString("child") ); while (!e.isNull()) { prop = e.attribute( QString("dynamicProperty") ); serialItem = RS_PROPERTY(prop.toAscii().constData()); if (serialItem) serialItem->fromXml(e); e = e.nextSiblingElement(QString("child")); } } e = n.firstChildElement( QString("ext" ) ); extFromXml(e); }
void ToolTip::hideEvent(QHideEvent *e) { QWidget::hideEvent(e); d->animation->stop(); QObject *source = d->source.data(); if (source && source->metaObject()->indexOfMethod("toolTipHidden()") != -1) { QMetaObject::invokeMethod(source, "toolTipHidden"); } WindowEffects::highlightWindows(winId(), QList<WId>()); }
void MetaDataBase::doConnections( QObject *o ) { setupDataBase(); MetaDataBaseRecord *r = db->find( (void*)o ); if ( !r ) { qWarning( "No entry for %p (%s, %s) found in MetaDataBase", o, o->name(), o->className() ); return; } QObject *sender = 0, *receiver = 0; QObjectList *l = 0; QValueList<Connection>::Iterator it = r->connections.begin(); for ( ; it != r->connections.end(); ++it ) { Connection conn = *it; if ( qstrcmp( conn.sender->name(), o->name() ) == 0 ) { sender = o; } else { l = o->queryList( 0, conn.sender->name(), false ); if ( !l || !l->first() ) { delete l; continue; } sender = l->first(); delete l; } if ( qstrcmp( conn.receiver->name(), o->name() ) == 0 ) { receiver = o; } else { l = o->queryList( 0, conn.receiver->name(), false ); if ( !l || !l->first() ) { delete l; continue; } receiver = l->first(); delete l; } QString s = "2""%1"; s = s.arg( conn.signal ); QString s2 = "1""%1"; s2 = s2.arg( conn.slot ); QStrList signalList = sender->metaObject()->signalNames( true ); QStrList slotList = receiver->metaObject()->slotNames( true ); // avoid warnings if ( signalList.find( conn.signal ) == -1 || slotList.find( conn.slot ) == -1 ) continue; QObject::connect( sender, s, receiver, s2 ); } }
void mafObjectBase::updateUI(QObject *selfUI) { if (selfUI == NULL) { return; } QList<QObject *> widgetList = qFindChildren<QObject *>(selfUI, QString()); int i = 0, size = widgetList.count(); for(; i<size; ++i) { bool propertyIsAWidget = true; QObject *widget = widgetList.at(i); QString widgetName = widget->objectName(); //widget name should be the name of the property of the class QVariant value = this->property(widgetName.toAscii()); if(!value.isValid()) { //qWarning(mafTr("Property with name %1 doesn't exist").arg(widgetName).toAscii()); //continue; propertyIsAWidget = false; } if (propertyIsAWidget) { const QMetaObject *metaobject = widget->metaObject(); int count = metaobject->propertyCount(); //check the property and change the value for (int i=0; i<count; ++i) { QMetaProperty metaproperty = metaobject->property(i); if(!metaproperty.isUser()) { continue; } const char *name = metaproperty.name(); widget->setProperty(name,value); break; } } //Set property of the widgets const QMetaObject *metaobject = this->metaObject(); int count = metaobject->propertyCount(); for (int i=0; i<count; ++i) { QMetaProperty metaproperty = metaobject->property(i); const char *name = metaproperty.name(); QString propertyName(name); if (propertyName.contains("_")){ int index = propertyName.indexOf("_"); QString propWidgetName = propertyName.left(index); QString propName = propertyName.mid(index+1); if (propWidgetName.compare(widgetName) == 0){ widget->setProperty(propName.toAscii(), this->property(propertyName.toAscii())); } } } } }
static int qt_connect(lua_State *L) { // LUA: "qt.connect(object signal closure)" // Connects signal to closure. // LUA: "qt.connect(object signal object signal_or_slot)" // Connects signal to signal or slot. QObject *obj = luaQ_checkqobject<QObject>(L, 1); const char *sig = luaL_checkstring(L, 2); QObject *robj = luaQ_toqobject(L, 3); if (robj) { // search signal or slot QByteArray rsig = luaL_checkstring(L, 4); const QMetaObject *mo = robj->metaObject(); int idx = mo->indexOfMethod(rsig.constData()); if (idx < 0) { rsig = QMetaObject::normalizedSignature(rsig.constData()); idx = mo->indexOfMethod(rsig.constData()); if (idx < 0) luaL_error(L, "cannot find target slot or signal %s", rsig.constData()); } // prepend signal or slot indicator QMetaMethod method = mo->method(idx); if (method.methodType() == QMetaMethod::Signal) rsig.prepend('0' + QSIGNAL_CODE); else if (method.methodType() == QMetaMethod::Slot) rsig.prepend('0' + QSLOT_CODE); else luaL_error(L, "target %s is not a slot or a signal", rsig.constData()); // connect QByteArray ssig = sig; ssig.prepend('0' + QSIGNAL_CODE); if (! QObject::connect(obj, ssig.constData(), robj, rsig.constData())) luaL_error(L, "cannot find source signal %s", sig); } else { luaL_checktype(L, 3, LUA_TFUNCTION); bool direct = lua_toboolean(L, 4); if (direct) luaL_checktype(L, 4, LUA_TBOOLEAN); if (! luaQ_connect(L, obj, sig, 3, direct)) luaL_error(L, "cannot find source signal %s", sig); } return 0; }
int objectGetProperty(QObject_ *object, const char *name, DataValue *result) { QObject *qobject = reinterpret_cast<QObject *>(object); QVariant var = qobject->property(name); packDataValue(&var, result); if (!var.isValid() && qobject->metaObject()->indexOfProperty(name) == -1) { // TODO May have to check the dynamic property names too. return 0; } return 1; }
AbstractParam::AbstractParam( QObject *parent, const char* name, QVariant::Type type ) : QObject(parent), m_type(type) { setObjectName(name); QObject *p = parent; if (p) { const QMetaObject *meta = p->metaObject(); if (meta->indexOfSlot("setDirty()") >= 0) { connect(this, SIGNAL(dirty()), p, SLOT(setDirty())); } } }
bool Serialization::SerializeToXML(const QObject &obj, QString name) { try { //????? QFile::remove(name); //????? QDomDocument doc; QDomElement root = doc.createElement(obj.metaObject()->className()); doc.appendChild(root); for(int i = 0; i < obj.metaObject()->propertyCount(); i++) { const QMetaProperty prop = obj.metaObject()->property(i); QString propName = prop.name(); if(propName == "objectName") continue; QDomElement el = doc.createElement(propName); QVariant value = obj.property(propName.toLocal8Bit().data()); QDomText txt = doc.createTextNode( value.toString() ); el.appendChild(txt); root.appendChild(el); } QFile output(name); if (output.open(QFile::ReadWrite)) { QTextStream stream(&output); doc.save(stream, 2); return true; } return false; } catch(...) { return false; } }
void SimApplication::response( const QSimTerminalResponse& resp ) { // Save the target information. QObject *target = d->target; const char *slot = d->slot; // Clear the command details, in preparation for a new command. if ( resp.command().type() != QSimCommand::SetupMenu ) { d->expectedType = QSimCommand::NoCommand; d->currentCommand = QByteArray(); } d->target = 0; d->slot = 0; // Process the response. d->inResponse = true; if ( target && slot ) { // Invoke the slot and pass "resp" to it. QByteArray name( slot + 1 ); name = QMetaObject::normalizedSignature( name.constData() ); int index = target->metaObject()->indexOfMethod( name.constData() ); if ( index != -1 ) { void *args[2]; args[0] = 0; args[1] = (void *)&resp; target->qt_metacall ( QMetaObject::InvokeMetaMethod, index, args ); } } d->inResponse = false; // Answer the AT+CSIM command and send notification of the new command. if ( !d->rules ) return; if ( d->currentCommand.isEmpty() || resp.command().type() == QSimCommand::SetupMenu ) { // No new command, so respond with a simple OK. d->rules->respond( "+CSIM: 4,9000\nOK" ); } else { // There is a new command, so send back 91XX to the TERMINAL RESPONSE // or ENVELOPE request to indicate that we have another command to // be fetched. Then send the unsolicited "*TCMD" notification. QByteArray data; data += (char)0x91; data += (char)(d->currentCommand.size()); d->rules->respond( "+CSIM: " + QString::number( data.size() * 2 ) + "," + QAtUtils::toHex( data ) + "\nOK" ); d->rules->unsolicited ( "*TCMD: " + QString::number( d->currentCommand.size() ) ); } }
bool Plugin::wrap(QObject* plugin) { const QMetaObject* interfaceMetaObject = metaObject(); const QMetaObject* wrappedMetaObject = plugin->metaObject(); int max = interfaceMetaObject->methodCount(); QObject o; int min = o.metaObject()->methodCount(); int nbInterfaceMethods = 0; QList<QByteArray> missingSignals; QList<QByteArray> missingSlots; QByteArray signalCode(QByteArray::number(QSIGNAL_CODE)); for (int i = min; i < max; ++i) { QMetaMethod method(interfaceMetaObject->method(i)); switch (method.methodType()) { case QMetaMethod::Signal: { ++nbInterfaceMethods; if (checkMethod(&method, wrappedMetaObject, &missingSignals)) { QByteArray connectSignature = signalCode + method.signature(); connect(plugin, connectSignature, this, connectSignature); } break; } case QMetaMethod::Slot: { ++nbInterfaceMethods; checkMethod(&method, wrappedMetaObject, &missingSlots); break; } default: break; } } bool ok = missingSignals.isEmpty() && missingSlots.isEmpty(); if (ok) { m_wrapped = plugin; } else { int missingMethods = missingSignals.count() + missingSlots.count(); if (missingMethods > 0 && missingMethods < nbInterfaceMethods - 1) { // Interface parially defined. qWarning(tr("%1 only partially implements interface %2.").arg(plugin->objectName()).arg(interfaceMetaObject->className()).toAscii()); if (!missingSignals.isEmpty()) { qWarning(tr("\tMissing signals:").toAscii()); foreach(const char* signal, missingSignals) { QString s("\t\t"); s += signal; qWarning(s.toAscii()); } }