本文整理汇总了C++中QMetaMethod::invoke方法的典型用法代码示例。如果您正苦于以下问题:C++ QMetaMethod::invoke方法的具体用法?C++ QMetaMethod::invoke怎么用?C++ QMetaMethod::invoke使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QMetaMethod
的用法示例。
在下文中一共展示了QMetaMethod::invoke方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: invoke
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]);
}
示例2: errorf
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);
}
示例3: eventFilter
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;
}
示例4: invokeMethod
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());
}
示例5: on_temp_returnPressed
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);
}
}
开发者ID:sandeepmanandhargithub,项目名称:Toolbox-ComputerVision,代码行数:33,代码来源:mainwindow+(Inspiron-5420's+conflicted+copy+2015-04-09).cpp
示例6: doCall
// 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;
}
示例7: queue_threshold_timeout
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) ;
}
示例8: _replyFinished
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 );
}
}
示例9: syncAndRender
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();
}
示例10: invokeDataChanged
// 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);
}
示例11: metaObject
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;
}
示例12: notifyBackend
/*!
* 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);
}
示例13: callMethodRecursively
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);
}
}
示例14: doCallMethod
/*!
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("");
}
示例15: invoke_signal
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) ;
}