void InvokerBase::invoke(QObject *t, const char *slot) { target = t; success = false; sig.append(slot, qstrlen(slot)); sig.append('('); for (int paramCount = 0; paramCount < lastArg; ++paramCount) { if (paramCount) sig.append(','); const char *type = arg[paramCount].name(); sig.append(type, strlen(type)); } sig.append(')'); sig.append('\0'); int idx = target->metaObject()->indexOfMethod(sig.constData()); if (idx < 0) return; QMetaMethod method = target->metaObject()->method(idx); if (useRet) success = method.invoke(target, connectionType, ret, arg[0], arg[1], arg[2], arg[3], arg[4], arg[5], arg[6], arg[7], arg[8], arg[9]); else success = method.invoke(target, connectionType, arg[0], arg[1], arg[2], arg[3], arg[4], arg[5], arg[6], arg[7], arg[8], arg[9]); }
error *objectInvoke(QObject_ *object, const char *method, int methodLen, DataValue *resultdv, DataValue *paramsdv, int paramsLen) { QObject *qobject = reinterpret_cast<QObject *>(object); QVariant result; QVariant param[MaxParams]; QGenericArgument arg[MaxParams]; for (int i = 0; i < paramsLen; i++) { unpackDataValue(¶msdv[i], ¶m[i]); arg[i] = Q_ARG(QVariant, param[i]); } if (paramsLen > 10) { panicf("fix the parameter dispatching"); } const QMetaObject *metaObject = qobject->metaObject(); // Walk backwards so descendants have priority. for (int i = metaObject->methodCount()-1; i >= 0; i--) { QMetaMethod metaMethod = metaObject->method(i); QMetaMethod::MethodType methodType = metaMethod.methodType(); if (methodType == QMetaMethod::Method || methodType == QMetaMethod::Slot) { QByteArray name = metaMethod.name(); if (name.length() == methodLen && qstrncmp(name.constData(), method, methodLen) == 0) { if (metaMethod.parameterCount() < paramsLen) { // TODO Might continue looking to see if a different signal has the same name and enough arguments. return errorf("method \"%s\" has too few parameters for provided arguments", method); } bool ok; if (metaMethod.returnType() == QMetaType::Void) { ok = metaMethod.invoke(qobject, Qt::DirectConnection, arg[0], arg[1], arg[2], arg[3], arg[4], arg[5], arg[6], arg[7], arg[8], arg[9]); } else { ok = metaMethod.invoke(qobject, Qt::DirectConnection, Q_RETURN_ARG(QVariant, result), arg[0], arg[1], arg[2], arg[3], arg[4], arg[5], arg[6], arg[7], arg[8], arg[9]); } if (!ok) { return errorf("invalid parameters to method \"%s\"", method); } packDataValue(&result, resultdv); return 0; } } } return errorf("object does not expose a method \"%s\"", method); }
bool DialogCallbacks::eventFilter(QObject *object, QEvent *event) { if (event->type() == QEvent::Close) { int index = m_view->metaObject()->indexOfMethod("dialogCanClose()"); if (index != -1) { QVariant returnedValue; returnedValue.setValue<bool>(true); QMetaMethod metaMethod = m_view->metaObject()->method(index); metaMethod.invoke(m_view, Q_RETURN_ARG(QVariant, returnedValue)); if (!returnedValue.toBool()) { event->ignore(); return true; } } QMainWindow* mainWindow = qobject_cast<QMainWindow*>(object); if (mainWindow) mainWindowGeometry = mainWindow->saveGeometry(); } return false; }
void PropertyController::invokeMethod(Qt::ConnectionType connectionType) { if (!m_object) { m_methodLogModel->appendRow(new QStandardItem(tr("%1: Invocation failed: Invalid object, probably got deleted in the meantime.") .arg(QTime::currentTime().toString("HH:mm:ss.zzz")))); return; } QMetaMethod method; QItemSelectionModel* selectionModel = ObjectBroker::selectionModel(m_methodModel); if (selectionModel->selectedRows().size() == 1) { const QModelIndex index = selectionModel->selectedRows().first(); method = index.data(ObjectMethodModelRole::MetaMethod).value<QMetaMethod>(); } if (method.methodType() != QMetaMethod::Slot) { m_methodLogModel->appendRow(new QStandardItem(tr("%1: Invocation failed: Invalid method (not a slot?).") .arg(QTime::currentTime().toString("HH:mm:ss.zzz")))); return; } const QVector<MethodArgument> args = m_methodArgumentModel->arguments(); // TODO retrieve return value and add it to the log in case of success // TODO measure executation time and that to the log const bool result = method.invoke(m_object.data(), connectionType, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9]); if (!result) { m_methodLogModel->appendRow(new QStandardItem(tr("%1: Invocation failed..").arg(QTime::currentTime().toString("HH:mm:ss.zzz")))); return; } m_methodArgumentModel->setMethod(QMetaMethod()); }
void MainWindow::on_temp_returnPressed() { if(activeCam()){ QString slotName = ui->temp->text() + "()"; int d = camui->sm->metaObject()->indexOfSlot(slotName.toStdString().c_str()); print(ui->temp->text(), CMD); if(d < 0) { print(ui->temp->text() + QString(" - no such command"), WARNING); return; } camui->sm->commandList.push_back(d); qDebug()<<"mainWin camui: "<<camui->sm->commandList.size(); // camui->sm->kernel = k2D.kernel; } /******************if image***************/ if(activeMdiChild()){ CvGlWidget *actCV = activeMdiChild(); this->sm->inIm = actCV->cvImage; QString slotName = ui->temp->text() + "()"; int d = this->sm->metaObject()->indexOfSlot(slotName.toStdString().c_str()); QMetaMethod method = this->sm->metaObject()->method(d); method.invoke(sm); actCV->showImage(actCV->cvImage); } }
// based on https://gist.github.com/andref/2838534. bool JsonRpcServer::doCall(QObject* object, const QMetaMethod& meta_method, QVariantList& converted_args, QVariant& return_value) { QList<QGenericArgument> arguments; for (int i = 0; i < converted_args.size(); i++) { // Notice that we have to take a reference to the argument, else we'd be // pointing to a copy that will be destroyed when this loop exits. QVariant& argument = converted_args[i]; // A const_cast is needed because calling data() would detach the // QVariant. QGenericArgument generic_argument( QMetaType::typeName(argument.userType()), const_cast<void*>(argument.constData()) ); arguments << generic_argument; } const char* return_type_name = meta_method.typeName(); int return_type = QMetaType::type(return_type_name); if (return_type != QMetaType::Void) { return_value = QVariant(return_type, nullptr); } QGenericReturnArgument return_argument( return_type_name, const_cast<void*>(return_value.constData()) ); // perform the call bool ok = meta_method.invoke( object, Qt::DirectConnection, return_argument, arguments.value(0), arguments.value(1), arguments.value(2), arguments.value(3), arguments.value(4), arguments.value(5), arguments.value(6), arguments.value(7), arguments.value(8), arguments.value(9) ); if (!ok) { // qDebug() << "calling" << meta_method.methodSignature() << "failed."; return false; } logInfo(logInvoke(meta_method, converted_args, return_value)); return true; }
void Timed::queue_threshold_timeout() { short_save_threshold_timer->stop() ; long_save_threshold_timer->stop() ; int method_index = this->metaObject()->indexOfMethod("save_event_queue()") ; QMetaMethod method = this->metaObject()->method(method_index) ; method.invoke(this, Qt::QueuedConnection) ; }
void _replyFinished() { Q_Q( NetworkAccessManagerProxy ); QNetworkReply *reply = static_cast<QNetworkReply*>( q->sender() ); KUrl url = reply->request().url(); QList<CallBackData*> callbacks = urlMap.values( url ); urlMap.remove( url ); QByteArray data = reply->readAll(); data.detach(); // detach so the bytes are not deleted before methods are invoked foreach( const CallBackData *cb, callbacks ) { // There may have been a redirect. KUrl redirectUrl = q->getRedirectUrl( reply ); // Check if there's no redirect. if( redirectUrl.isEmpty() ) { QByteArray sig = QMetaObject::normalizedSignature( cb->method ); sig.remove( 0, 1 ); // remove first char, which is the member code (see qobjectdefs.h) // and let Qt's meta object system handle the rest. if( cb->receiver ) { bool success( false ); const QMetaObject *mo = cb->receiver.data()->metaObject(); int methodIndex = mo->indexOfSlot( sig ); if( methodIndex != -1 ) { Error err = { reply->error(), reply->errorString() }; QMetaMethod method = mo->method( methodIndex ); success = method.invoke( cb->receiver.data(), cb->type, Q_ARG( KUrl, reply->request().url() ), Q_ARG( QByteArray, data ), Q_ARG( NetworkAccessManagerProxy::Error, err ) ); } if( !success ) { debug() << QString( "Failed to invoke method %1 of %2" ) .arg( QString(sig) ).arg( mo->className() ); } } } else { debug() << "the server is redirecting the request to: " << redirectUrl; // Let's try to fetch the data again, but this time from the new url. QNetworkReply *newReply = q->getData( redirectUrl, cb->receiver.data(), cb->method, cb->type ); emit q->requestRedirected( url, redirectUrl ); emit q->requestRedirected( reply, newReply ); } }
void QWinRTAbstractVideoRendererControl::syncAndRender() { qCDebug(lcMMVideoRender) << __FUNCTION__; Q_D(QWinRTAbstractVideoRendererControl); QThread *currentThread = QThread::currentThread(); const QMetaMethod present = staticMetaObject.method(staticMetaObject.indexOfMethod("present()")); forever { if (currentThread->isInterruptionRequested()) break; { CriticalSectionLocker lock(&d->mutex); HRESULT hr; if (d->dirtyState == TextureDirty) { CD3D11_TEXTURE2D_DESC desc(DXGI_FORMAT_B8G8R8A8_UNORM, d->format.frameWidth(), d->format.frameHeight(), 1, 1); desc.BindFlags |= D3D11_BIND_RENDER_TARGET; desc.MiscFlags = D3D11_RESOURCE_MISC_SHARED; hr = g->device->CreateTexture2D(&desc, NULL, d->texture.ReleaseAndGetAddressOf()); BREAK_IF_FAILED("Failed to get create video texture"); ComPtr<IDXGIResource> resource; hr = d->texture.As(&resource); BREAK_IF_FAILED("Failed to cast texture to resource"); hr = resource->GetSharedHandle(&d->shareHandle); BREAK_IF_FAILED("Failed to get texture share handle"); d->dirtyState = SurfaceDirty; } hr = g->output->WaitForVBlank(); CONTINUE_IF_FAILED("Failed to wait for vertical blank"); bool success = false; switch (d->blitMode) { case DirectVideo: success = render(d->texture.Get()); break; case MediaFoundation: success = dequeueFrame(&d->presentFrame); break; default: success = false; } if (!success) continue; // Queue to the control's thread for presentation present.invoke(this, Qt::QueuedConnection); currentThread->eventDispatcher()->processEvents(QEventLoop::AllEvents); } } // All done, exit render loop currentThread->quit(); }
// Convenience methods for invoking the QSFPM Q_SLOTS. Those slots must be invoked with invokeMethod // because they are Q_PRIVATE_SLOTs inline void invokeDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int>()) { Q_Q(KRecursiveFilterProxyModel); bool success = false; if (passRolesToDataChanged()) { // required for Qt 5.5 and upwards, see commit f96baeb75fc in qtbase static const QMetaMethod m = findMethod("_q_sourceDataChanged(QModelIndex,QModelIndex,QVector<int>)"); success = m.invoke(q, Qt::DirectConnection, Q_ARG(QModelIndex, topLeft), Q_ARG(QModelIndex, bottomRight), Q_ARG(QVector<int>, roles)); } else { // backwards compatibility static const QMetaMethod m = findMethod("_q_sourceDataChanged(QModelIndex,QModelIndex)"); success = m.invoke(q, Qt::DirectConnection, Q_ARG(QModelIndex, topLeft), Q_ARG(QModelIndex, bottomRight)); } Q_UNUSED(success); Q_ASSERT(success); }
void Context::Applet::showWarning( const QString &message, const char *slot ) { int ret = KMessageBox::warningYesNo( 0, message ); Plasma::MessageButton button = (ret == KMessageBox::Yes) ? Plasma::ButtonYes : Plasma::ButtonNo; QByteArray sig = QMetaObject::normalizedSignature( slot ); sig.remove( 0, 1 ); // remove method type QMetaMethod me = metaObject()->method( metaObject()->indexOfSlot(sig) ); QGenericArgument arg1 = Q_ARG( const Plasma::MessageButton, button ); if( !me.invoke( this, arg1 ) ) warning() << "invoking failed:" << sig; }
/*! * This will start or append \a change to a batch of changes from frontend * nodes. Once the batch is complete, when the event loop returns, the batch is * sent to the QChangeArbiter to notify the backend aspects. */ void QPostman::notifyBackend(const QSceneChangePtr &change) { // If batch in progress // add change // otherwise start batch // by calling a queued slot Q_D(QPostman); if (d->m_batch.empty()) { static const QMetaMethod submitChangeBatch = submitChangeBatchMethod(); submitChangeBatch.invoke(this, Qt::QueuedConnection); } d->m_batch.push_back(change); }
static void callMethodRecursively(QObject *obj, const char *method_name) { if(!obj) return; int ix = obj->metaObject()->indexOfMethod(method_name); if(ix >= 0) { QMetaMethod mm = obj->metaObject()->method(ix); mm.invoke(obj); } Q_FOREACH(auto o, obj->children()) { callMethodRecursively(o, method_name); } }
/*! Function for executing a slot that does not take parameters */ QString ObjectService::doCallMethod(TasCommand* command, QObject* target, QString& errorString) { Q_ASSERT(command->name() == "CallMethod"); QString methodName = command->parameter("method_name"); TasLogger::logger()->debug("name: " + methodName); int methodId = target->metaObject()->indexOfMethod( QMetaObject::normalizedSignature(methodName.toLatin1()).constData()); if (methodId == -1){ errorString.append(methodName + " method not found on object. "); TasLogger::logger()->debug("...method not found on object"); } else{ QMetaMethod metaMethod = target->metaObject()->method(methodId); QVariantList args = parseArguments(command); QList<QGenericArgument> arguments; for (int i = 0; i < args.size(); i++) { QVariant& argument = args[i]; QGenericArgument genericArgument( QMetaType::typeName(argument.userType()), const_cast<void*>(argument.constData())); arguments << genericArgument; } QVariant returnValue(QMetaType::type(metaMethod.typeName()), static_cast<void*>(NULL)); QGenericReturnArgument returnArgument( metaMethod.typeName(), const_cast<void*>(returnValue.constData())); if (!metaMethod.invoke( target, Qt::AutoConnection, // In case the object is in another thread. returnArgument, arguments.value(0), arguments.value(1), arguments.value(2), arguments.value(3), arguments.value(4), arguments.value(5), arguments.value(6), arguments.value(7), arguments.value(8), arguments.value(9))) { errorString.append(methodName + " method invocation failed! "); } else { return returnValue.toString(); } } return QString(""); }
void Timed::invoke_signal(const nanotime_t &back) { log_debug("systime_back=%s, back=%s", systime_back.str().c_str(), back.str().c_str()) ; systime_back += back ; log_debug("new value: systime_back=%s", systime_back.str().c_str()) ; if(signal_invoked) return ; signal_invoked = true ; int methodIndex = this->metaObject()->indexOfMethod("send_time_settings()") ; QMetaMethod method = this->metaObject()->method(methodIndex); method.invoke(this, Qt::QueuedConnection); log_assert(q_pause==NULL) ; q_pause = new machine_t::pause_t(am) ; log_debug("new q_pause=%p", q_pause) ; }
void QpBelongsToManyBase::add(QSharedPointer<QObject> object) { QList<QSharedPointer<QObject>> obj = objects(); Q_UNUSED(obj); // resolve and keep a strong ref, while we're working here QWeakPointer<QObject> weakRef = object.toWeakRef(); if(data->objects.contains(weakRef)) return; data->objects.append(weakRef); QpMetaProperty reverse = data->metaProperty.reverseRelation(); QSharedPointer<QObject> sharedParent = Qp::sharedFrom(data->parent); if(object){ if(reverse.isToOneRelationProperty()) { reverse.write(object.data(), Qp::Private::variantCast(sharedParent)); } else { QString className = data->metaProperty.metaObject().className(); QSharedPointer<QObject> shared = Qp::sharedFrom(data->parent); QVariant wrapper = Qp::Private::variantCast(shared, className); const QMetaObject *mo = object->metaObject(); QByteArray methodName = reverse.metaObject().addObjectMethod(reverse).methodSignature(); int index = mo->indexOfMethod(methodName); Q_ASSERT_X(index > 0, Q_FUNC_INFO, QString("You have to add a public slot with the signature '%1' to your '%2' class!") .arg(QString::fromLatin1(methodName)) .arg(mo->className()) .toLatin1()); QMetaMethod method = mo->method(index); Q_ASSERT(method.invoke(object.data(), Qt::DirectConnection, QGenericArgument(data->metaProperty.typeName().toLatin1(), wrapper.data()))); } } }
void KMenu::mouseReleaseEvent(QMouseEvent* e) { // Save the button, and the modifiers d->keyboardModifiers = e->modifiers(); d->mouseButtons = e->buttons(); if ( e->button() == Qt::MidButton) { if(activeAction() ) { const QMetaObject *metaObject = activeAction()->metaObject(); const int index = metaObject->indexOfMethod("triggered(Qt::MouseButtons,Qt::KeyboardModifiers)"); if (index != -1) { const QMetaMethod method = metaObject->method(index); method.invoke(activeAction(), Qt::DirectConnection, Q_ARG(Qt::MouseButtons, e->button()), Q_ARG(Qt::KeyboardModifiers, QApplication::keyboardModifiers() )); } } return; } if ( !d->ctxMenu || !d->ctxMenu->isVisible() ) QMenu::mouseReleaseEvent(e); }
bool QObjectProxy::invokeMethod( const char *method, PyrSlot *retSlot, PyrSlot *argSlot, Qt::ConnectionType ctype ) { mutex.lock(); if( !qObject ) { mutex.unlock(); return true; } // the signature char array QVarLengthArray<char, 512> sig; // serialize method name int len = qstrlen( method ); if( len <= 0 ) { mutex.unlock(); return false; } sig.append( method, len ); sig.append( '(' ); // get data from argument slots QtCollider::Variant argSlots[10]; if( isKindOfSlot( argSlot, class_Array ) ) { PyrSlot *slots = slotRawObject( argSlot )->slots; int size = slotRawObject( argSlot )->size; int i; for( i = 0; i<size && i<10; ++i ) { argSlots[i].setData( slots ); ++slots; } } else argSlots[0].setData( argSlot ); // serialize argument types int i; for( i = 0; i < 10; ++i ) { int type = argSlots[i].type(); if( type == QMetaType::Void ) break; const char *typeName = QMetaType::typeName( type ); int len = qstrlen( typeName ); if( len <= 0 ) break; sig.append( typeName, len ); sig.append( ',' ); } // finalize the signature if( i==0 ) sig.append( ')' ); else sig[sig.size() - 1] = ')'; sig.append('\0'); // get the meta method const QMetaObject *mo = qObject->metaObject(); int mi = mo->indexOfMethod( sig.constData() ); if( mi < 0 ) { QByteArray mnorm = QMetaObject::normalizedSignature( sig.constData() ); mi = mo->indexOfMethod( mnorm.constData() ); } if( mi < 0 || mi >= mo->methodCount() ) { qcProxyDebugMsg( 1, QString("WARNING: No such method: %1::%2").arg( mo->className() ) .arg( sig.constData() ) ); mutex.unlock(); return false; } QMetaMethod mm = mo->method( mi ); // construct the return data object QGenericReturnArgument retGArg; const char *retTypeName = mm.typeName(); int retType = QMetaType::type( retTypeName ); void *retPtr = 0; if( retSlot ) { retPtr = QMetaType::construct( retType ); retGArg = QGenericReturnArgument( retTypeName, retPtr ); } //do it! bool success = mm.invoke( qObject, ctype, retGArg, argSlots[0].asGenericArgument(), argSlots[1].asGenericArgument(), argSlots[2].asGenericArgument(), argSlots[3].asGenericArgument(), argSlots[4].asGenericArgument(), argSlots[5].asGenericArgument(), argSlots[6].asGenericArgument(), argSlots[7].asGenericArgument(), argSlots[8].asGenericArgument(), argSlots[9].asGenericArgument()); // store the return data into the return slot if( success && retPtr ) { QVariant retVar( retType, retPtr ); Slot::setVariant( retSlot, retVar ); }; if( retPtr ) QMetaType::destroy( retType, retPtr ); mutex.unlock(); return success; }
// The type call slot. static PyObject *pyqtMethodProxy_call(PyObject *self, PyObject *args, PyObject *kw_args) { qpycore_pyqtMethodProxy *mp = (qpycore_pyqtMethodProxy *)self; const char *py_name = mp->py_name->constData(); // Check for keyword arguments. if (kw_args) { PyErr_Format(PyExc_TypeError, "%s() does not support keyword arguments", py_name); return 0; } QMetaMethod method = mp->qobject->metaObject()->method(mp->method_index); QList<QByteArray> arg_types = method.parameterTypes(); if (PyTuple_Size(args) != arg_types.size()) { PyErr_Format(PyExc_TypeError, "%s() called with %zd arguments but %d expected", py_name, PyTuple_Size(args), arg_types.size()); return 0; } // Parse the return type and the arguments. QGenericReturnArgument ret; QGenericArgument a0, a1, a2, a3, a4, a5, a6, a7, a8, a9; Chimera::Storage *return_storage, *storage[10]; QByteArray return_type(method.typeName()); bool failed = false; return_storage = 0; if (!return_type.isEmpty()) { const Chimera *ct = Chimera::parse(return_type); if (!ct) { PyErr_Format(PyExc_TypeError, "unable to convert return value of %s from '%s' to a Python object", py_name, return_type.constData()); return 0; } return_storage = ct->storageFactory(); ret = QGenericReturnArgument(return_type.constData(), return_storage->address()); } parse_arg(args, 0, arg_types, a0, storage, failed, py_name); parse_arg(args, 1, arg_types, a1, storage, failed, py_name); parse_arg(args, 2, arg_types, a2, storage, failed, py_name); parse_arg(args, 3, arg_types, a3, storage, failed, py_name); parse_arg(args, 4, arg_types, a4, storage, failed, py_name); parse_arg(args, 5, arg_types, a5, storage, failed, py_name); parse_arg(args, 6, arg_types, a6, storage, failed, py_name); parse_arg(args, 7, arg_types, a7, storage, failed, py_name); parse_arg(args, 8, arg_types, a8, storage, failed, py_name); parse_arg(args, 9, arg_types, a9, storage, failed, py_name); // Invoke the method. PyObject *result = 0; if (!failed) { failed = !method.invoke(mp->qobject, ret, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9); if (failed) { PyErr_Format(PyExc_TypeError, "invocation of %s() failed", py_name); } else if (return_storage) { result = return_storage->toPyObject(); } else { result = Py_None; Py_INCREF(result); } } // Release any storage. if (return_storage) { delete return_storage->type(); delete return_storage; } for (int i = 0; i < 10; ++i) { Chimera::Storage *st = storage[i]; if (st) { delete st->type(); delete st; } } return result; }
void QGraphicsWebViewPrivate::markForSync(bool scheduleSync) { shouldSync = true; if (scheduleSync) syncMetaMethod.invoke(q, Qt::QueuedConnection); }
void machine_t::invoke_process_transition_queue() { int methodIndex = this->metaObject()->indexOfMethod("process_transition_queue()"); QMetaMethod method = this->metaObject()->method(methodIndex); method.invoke(this, Qt::QueuedConnection); }
void QpBelongsToOneBase::setObject(const QSharedPointer<QObject> newObject) const { QSharedPointer<QObject> previousObject = object(); data->cleared = newObject.isNull(); if(previousObject == newObject) return; QpMetaProperty reverse = data->metaProperty.reverseRelation(); data->object = newObject.toWeakRef(); QSharedPointer<QObject> shared = Qp::sharedFrom(data->parent); if(previousObject) { if(reverse.isToOneRelationProperty()) { QString className = data->metaProperty.metaObject().className(); reverse.write(previousObject.data(), Qp::Private::variantCast(QSharedPointer<QObject>(), className)); } else { QVariant wrapper = Qp::Private::variantCast(shared); const QMetaObject *mo = previousObject->metaObject(); QByteArray methodName = reverse.metaObject().removeObjectMethod(reverse).methodSignature(); int index = mo->indexOfMethod(methodName); Q_ASSERT_X(index > 0, Q_FUNC_INFO, QString("You have to add a public slot with the signature '%1' to your '%2' class!") .arg(QString::fromLatin1(methodName)) .arg(mo->className()) .toLatin1()); QMetaMethod method = mo->method(index); Q_ASSERT(method.invoke(previousObject.data(), Qt::DirectConnection, QGenericArgument(data->metaProperty.typeName().toLatin1(), wrapper.data()))); } } if(newObject) { if(reverse.isToOneRelationProperty()) { reverse.write(newObject.data(), Qp::Private::variantCast(shared)); } else { QVariant wrapper = Qp::Private::variantCast(shared); const QMetaObject *mo = newObject->metaObject(); QByteArray methodName = reverse.metaObject().addObjectMethod(reverse).methodSignature(); int index = mo->indexOfMethod(methodName); Q_ASSERT_X(index > 0, Q_FUNC_INFO, QString("You have to add a public slot with the signature '%1' to your '%2' class!") .arg(QString::fromLatin1(methodName)) .arg(mo->className()) .toLatin1()); QMetaMethod method = mo->method(index); Q_ASSERT(method.invoke(newObject.data(), Qt::DirectConnection, QGenericArgument(data->metaProperty.typeName().toLatin1(), wrapper.data()))); } } // Set again, because it may happen, that resetting the previousObjects relation has also reset this value. data->object = newObject.toWeakRef(); }
void ChatEdit::send() { QString text = textEditToPlainText(); QString trimmed = text.trimmed(); if(!m_session || trimmed.isEmpty()) return; ChatUnit *unit = m_session->getCurrentUnit(); if (trimmed.startsWith(QLatin1Char('/')) && trimmed.size() > 1) { int index = trimmed.indexOf(QLatin1Char(' ')); QStringRef cmd = trimmed.midRef(1, (index == -1 ? trimmed.size() : index) - 1); const QMetaObject *meta = unit->metaObject(); for (int i = meta->propertyCount() - 1; i >= 0; --i) { QMetaProperty prop = meta->property(i); if (prop.isWritable() && QLatin1String(prop.name()) == cmd) { prop.write(unit, trimmed.mid(index + 1)); clear(); return; } } QByteArray signature = cmd.toString().toLatin1(); int methodIndex = meta->indexOfMethod(signature + "(QString)"); if (methodIndex != -1) { QMetaMethod method = meta->method(methodIndex); QString arg = trimmed.mid(index + 1); if (method.invoke(unit, Q_ARG(QString, arg))) { clear(); return; } } methodIndex = meta->indexOfMethod(signature + "(QVariant)"); if (methodIndex != -1) { QMetaMethod method = meta->method(methodIndex); QVariant arg = trimmed.mid(index + 1); if (method.invoke(unit, Q_ARG(QVariant, arg))) { clear(); return; } } methodIndex = meta->indexOfMethod(signature + "()"); if (methodIndex != -1) { QMetaMethod method = meta->method(methodIndex); if (method.invoke(unit)) { clear(); return; } } } Message message(text); message.setIncoming(false); message.setChatUnit(unit); message.setTime(QDateTime::currentDateTime()); qint64 result = m_session->appendMessage(message); if (MessageHandler::Error != -result) clear(); // if (!unit->sendMessage(message)) { // NotificationRequest request(Notification::System); // request.setObject(this); // request.setText(tr("Unable to send message to %1").arg(unit->title())); // request.send(); // } // else { // m_session->appendMessage(message); // clear(); // } }
void ChatEdit::send() { if (!isEnabled()) return; ChatEditLocker locker(this); QString text = textEditToPlainText(); QString trimmed = text.trimmed(); if(!m_session || trimmed.isEmpty()) return; ChatUnit *unit = m_session.data()->getCurrentUnit(); if (trimmed.startsWith(QLatin1Char('/')) && trimmed.size() > 1) { int index = trimmed.indexOf(QLatin1Char(' ')); QStringRef cmd = trimmed.midRef(1, (index == -1 ? trimmed.size() : index) - 1); const QMetaObject *meta = unit->metaObject(); for (int i = meta->propertyCount() - 1; i >= 0; --i) { QMetaProperty prop = meta->property(i); if (prop.isWritable() && QLatin1String(prop.name()) == cmd) { prop.write(unit, trimmed.mid(index + 1)); clear(); return; } } QByteArray signature = cmd.toString().toLatin1(); int methodIndex = meta->indexOfMethod(signature + "(QString)"); if (methodIndex != -1) { QMetaMethod method = meta->method(methodIndex); QString arg = trimmed.mid(index + 1); if (method.invoke(unit, Q_ARG(QString, arg))) { clear(); return; } } methodIndex = meta->indexOfMethod(signature + "(QVariant)"); if (methodIndex != -1) { QMetaMethod method = meta->method(methodIndex); QVariant arg = trimmed.mid(index + 1); if (method.invoke(unit, Q_ARG(QVariant, arg))) { clear(); return; } } methodIndex = meta->indexOfMethod(signature + "()"); if (methodIndex != -1) { QMetaMethod method = meta->method(methodIndex); if (method.invoke(unit)) { clear(); return; } } } Message message(text); message.setIncoming(false); message.setChatUnit(unit); message.setTime(QDateTime::currentDateTime()); MessageHandler::traceHandlers(); auto lockerPtr = QSharedPointer<ChatEditLocker>::create(std::move(locker)); QPointer<ChatEdit> edit(this); m_session->append(message, [edit, lockerPtr] (qint64 result, const Message &, const QString &) mutable { if (MessageHandler::Error != -result && edit) edit->clear(); lockerPtr.reset(); }); }
void QPostman::sceneChangeEvent(const QSceneChangePtr &e) { static const QMetaMethod notifyFrontendNode = notifyFrontendNodeMethod(); notifyFrontendNode.invoke(this, Q_ARG(QSceneChangePtr, e)); }