本文整理汇总了C++中QMetaMethod类的典型用法代码示例。如果您正苦于以下问题:C++ QMetaMethod类的具体用法?C++ QMetaMethod怎么用?C++ QMetaMethod使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QMetaMethod类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: hasMetaMethodStartingWith
static bool hasMetaMethodStartingWith(QObject *object, const QString &checkedSignature)
{
const QMetaObject *mo = object->metaObject();
bool found = false;
for (int methodIndex = 0; methodIndex < mo->methodCount(); ++methodIndex) {
QMetaMethod mm = mo->method(methodIndex);
QString signature = QString::fromLatin1(mm.methodSignature());
if (signature.startsWith(checkedSignature)) {
found = true;
break;
}
}
return found;
}
示例2: _invokeMethodEvery
void MethodViewer::_invokeMethodEvery() {
QAction *sender = static_cast<QAction*>(this->sender());
Item *item = sender->property("treeItem").value<MethodViewer::Item*>();
QMetaMethod method = item->getMethod();
bool bOk;
int interval = QInputDialog::getInt(this, tr("Invoke method %1 every...").arg(method.signature()),
tr("Interval in seconds"), 5, 1, 30, 1, &bOk);
if (!bOk) return;
m_invokedMethod = method;
m_invokedObject = item->getObject();
m_invokeTimer.start(interval*1000);
}
示例3: log_debug
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) ;
}
示例4: publicMethodIndex
static int publicMethodIndex(NPObject *npobj, NPIdentifier name)
{
NPClass_Prolog;
QByteArray qname = NPN_UTF8FromIdentifier(name);
const QMetaObject *metaObject = qobject->metaObject();
for (int slotIndex = metaOffset(metaObject, MetaMethod); slotIndex < metaObject->methodCount(); ++slotIndex) {
const QMetaMethod slot = qobject->metaObject()->method(slotIndex);
if (slot.access() != QMetaMethod::Public || slot.methodType() == QMetaMethod::Signal)
continue;
QByteArray signature = slot.signature();
if (signature.left(signature.indexOf('(')) == qname)
return slotIndex;
}
return -1;
}
示例5: Q_ASSERT
QDeclarativePropertyCache::Data QDeclarativePropertyCache::create(const QMetaObject *metaObject,
const QString &property)
{
Q_ASSERT(metaObject);
QDeclarativePropertyCache::Data rv;
{
const QMetaObject *cmo = metaObject;
while (cmo) {
int idx = metaObject->indexOfProperty(property.toUtf8());
if (idx != -1) {
QMetaProperty p = metaObject->property(idx);
if (p.isScriptable()) {
rv.load(metaObject->property(idx));
if (!isDynamicMetaObject(cmo))
rv.flags |= Data::IsDirect;
return rv;
} else {
while (cmo && cmo->propertyOffset() >= idx)
cmo = cmo->superClass();
}
} else {
cmo = 0;
}
}
}
int methodCount = metaObject->methodCount();
for (int ii = methodCount - 1; ii >= 3; --ii) { // >=3 to block the destroyed signal and deleteLater() slot
QMetaMethod m = metaObject->method(ii);
if (m.access() == QMetaMethod::Private)
continue;
QString methodName = QString::fromUtf8(m.signature());
int parenIdx = methodName.indexOf(QLatin1Char('('));
Q_ASSERT(parenIdx != -1);
QStringRef methodNameRef = methodName.leftRef(parenIdx);
if (methodNameRef == property) {
rv.load(m);
if (!isDynamicMetaObject(m.enclosingMetaObject()))
rv.flags |= Data::IsDirect;
return rv;
}
}
return rv;
}
示例6: listInterface
void listInterface(const QString &service, const QString &path, const QString &interface)
{
QDBusInterfacePtr iface(*connection, service, path, interface);
if (!iface->isValid()) {
QDBusError err(iface->lastError());
fprintf(stderr, "Interface '%s' not available in object %s at %s:\n%s (%s)\n",
qPrintable(interface), qPrintable(path), qPrintable(service),
qPrintable(err.name()), qPrintable(err.message()));
exit(1);
}
const QMetaObject *mo = iface->metaObject();
// properties
for (int i = mo->propertyOffset(); i < mo->propertyCount(); ++i) {
QMetaProperty mp = mo->property(i);
printf("property ");
if (mp.isReadable() && mp.isWritable())
printf("readwrite");
else if (mp.isReadable())
printf("read");
else
printf("write");
printf(" %s %s.%s\n", mp.typeName(), qPrintable(interface), mp.name());
}
// methods (signals and slots)
for (int i = mo->methodOffset(); i < mo->methodCount(); ++i) {
QMetaMethod mm = mo->method(i);
QByteArray signature = mm.signature();
signature.truncate(signature.indexOf('('));
printf("%s %s%s%s %s.%s(",
mm.methodType() == QMetaMethod::Signal ? "signal" : "method",
mm.tag(), *mm.tag() ? " " : "",
*mm.typeName() ? mm.typeName() : "void",
qPrintable(interface), signature.constData());
QList<QByteArray> types = mm.parameterTypes();
QList<QByteArray> names = mm.parameterNames();
bool first = true;
for (int i = 0; i < types.count(); ++i) {
printf("%s%s",
first ? "" : ", ",
types.at(i).constData());
if (!names.at(i).isEmpty())
printf(" %s", names.at(i).constData());
first = false;
}
printf(")\n");
}
}
示例7: findSignalId
int DynamicQObject::findSignalId(const char *signal)
{
#if 0
const QMetaObject *meta = obj->metaObject();
// Finding signal id
for (int i = meta->methodOffset(); i < meta->methodCount(); ++i) {
QMetaMethod method = meta->method(i);
const char *methodName = method.name().data();
if (strcmp(signal, methodName) == 0)
return i;
}
#endif
return -1;
}
示例8: publicMethodIndex
static int publicMethodIndex(NPObject *npobj, const QByteArray &slotName, int argCount = -1)
{
NPClass_Prolog;
const QMetaObject *metaObject = qobject->metaObject();
for (int slotIndex = metaOffset(metaObject, MetaMethod); slotIndex < metaObject->methodCount(); ++slotIndex) {
const QMetaMethod slot = qobject->metaObject()->method(slotIndex);
if (slot.access() != QMetaMethod::Public || slot.methodType() == QMetaMethod::Signal)
continue;
QByteArray signature = slot.signature();
if (signature.left(signature.indexOf('(')) == slotName) {
if (argCount == -1 || slot.parameterTypes().count() == argCount)
return slotIndex;
}
}
return -1;
}
示例9: isSignalConnected
bool QObject::isSignalConnected(const QMetaMethod &signalMetaMethod) const
{
bool retval = false;
const BentoAbstract *signalMethod_Bento = signalMetaMethod.getBentoBox();
std::unique_lock<std::mutex> senderLock{this->m_mutex_ToReceiver};
for(auto index = this->m_connectList_ToReceiver.begin(); index != this->m_connectList_ToReceiver.end(); ++index) {
const ConnectStruct &temp = *index;
if (*(temp.signalMethod) != *(signalMethod_Bento)) {
continue;
}
if (temp.sender == 0) {
// connection is marked for deletion
continue;
}
retval = true;
break;
}
return retval;
}
示例10: getMethodName
static inline QByteArray getMethodName(const QMetaMethod& method) {
QByteArray name(method.signature());
int bracket = name.indexOf("(");
if (bracket >= 0)
name.remove(bracket, name.size() - bracket);
return name;
}
示例11: Q_ASSERT_X
bool PacketReceiver::registerListener(PacketType type, QObject* listener, const char* slot,
bool deliverPending) {
Q_ASSERT_X(listener, "PacketReceiver::registerListener", "No object to register");
Q_ASSERT_X(slot, "PacketReceiver::registerListener", "No slot to register");
QMetaMethod matchingMethod = matchingMethodForListener(type, listener, slot);
if (matchingMethod.isValid()) {
qCDebug(networking) << "Registering a packet listener for packet list type" << type;
registerVerifiedListener(type, listener, matchingMethod, deliverPending);
return true;
} else {
qCWarning(networking) << "FAILED to Register a packet listener for packet list type" << type;
return false;
}
}
示例12: NPClass_Invoke
static bool NPClass_Invoke(NPObject *npobj, NPIdentifier name, const NPVariant *args, uint32 argCount, NPVariant *result)
{
NPClass_Prolog;
int slotIndex = publicMethodIndex(npobj, name);
if (slotIndex == -1) {
QByteArray qname = NPN_UTF8FromIdentifier(name);
NPN_SetException(npobj, QByteArray("No such method " + qname).constData());
return false;
}
const QMetaMethod slot = qobject->metaObject()->method(slotIndex);
QList<QByteArray> parameterTypes = slot.parameterTypes();
if (parameterTypes.count() != static_cast<int>(argCount)) {
QByteArray qname = NPN_UTF8FromIdentifier(name);
NPN_SetException(npobj, QByteArray("Wrong parameter count for method " + qname).constData());
return false;
}
QVariant returnVariant(QVariant::nameToType(slot.typeName()), (void *)0);
QVector<QVariant> variants(parameterTypes.count()); // keep data alive
QVector<const void *> metacallArgs(parameterTypes.count() + 1); // arguments for qt_metacall
metacallArgs[0] = returnVariant.data(); // args[0] == return value
for (int p = 0; p < parameterTypes.count(); ++p) {
QVariant::Type type = QVariant::nameToType(parameterTypes.at(p));
if (type == QVariant::Invalid) {
QByteArray qname = NPN_UTF8FromIdentifier(name);
NPN_SetException(npobj, QByteArray("Unsupported parameter in method " + qname).constData());
return false;
}
QVariant qvar = args[p];
if (!qvar.convert(type)) {
QByteArray qname = NPN_UTF8FromIdentifier(name);
NPN_SetException(npobj, QByteArray("Unsupported parameter value in method " + qname).constData());
return false;
}
variants[p] = qvar;
metacallArgs[p + 1] = variants.at(p).constData(); // must not detach!
}
qobject->qt_metacall(QMetaObject::InvokeMetaMethod, slotIndex, const_cast<void * *>(metacallArgs.data()));
if (returnVariant.isValid() && result)
*result = NPVariant::fromQVariant(This, returnVariant);
return true;
}
示例13: qt_qmetacall
/* We catch all qt_metacall invocations */
extern "C" SEXP qt_qmetacall(SEXP x, SEXP s_call, SEXP s_id, SEXP s_args)
{
SmokeObject *so = SmokeObject::fromSexp(x);
QMetaObject::Call call =
enum_from_sexp<QMetaObject::Call>(s_call, SmokeType());
int id = from_sexp<int>(s_id);
void **args = reinterpret_cast<void **>(from_sexp<void *>(s_args));
// Assume the target slot is a C++ one
Smoke::StackItem i[4];
i[1].s_enum = call;
i[2].s_int = id;
i[3].s_voidp = args;
so->invokeMethod("qt_metacall$$?", i);
int ret = i[0].s_int;
if (ret < 0) {
return ScalarInteger(ret);
}
if (call != QMetaObject::InvokeMetaMethod)
return ScalarInteger(id);
QObject * qobj = reinterpret_cast<QObject *>(so->castPtr("QObject"));
// get obj metaobject with a virtual call
const QMetaObject *metaobject = qobj->metaObject();
// get method count
int count = metaobject->methodCount();
QMetaMethod method = metaobject->method(id);
if (method.methodType() == QMetaMethod::Signal) {
// FIXME: this override of 'activate' is obsolete
metaobject->activate(qobj, id, (void**) args);
return ScalarInteger(id - count);
}
DynamicBinding binding(MocMethod(so->smoke(), metaobject, id));
QVector<SmokeType> stackTypes = binding.types();
MocStack mocStack = MocStack(args, stackTypes.size());
SmokeStack smokeStack = mocStack.toSmoke(stackTypes);
binding.invoke(so, smokeStack.items());
mocStack.returnFromSmoke(smokeStack, stackTypes[0]);
if (binding.lastError() == Method::NoError)
warning("Slot invocation failed for %s::%s", so->klass()->name(),
binding.name());
return ScalarInteger(id - count);
}
示例14: lastError
/*!
Places a call to the remote method specified by \a method on this interface, using \a args as
arguments. This function returns the message that was received as a reply, which can be a normal
QDBusMessage::ReplyMessage (indicating success) or QDBusMessage::ErrorMessage (if the call
failed). The \a mode parameter specifies how this call should be placed.
If the call succeeds, lastError() will be cleared; otherwise, it will contain the error this
call produced.
Normally, you should place calls using call().
\warning If you use \c UseEventLoop, your code must be prepared to deal with any reentrancy:
other method calls and signals may be delivered before this function returns, as well
as other Qt queued signals and events.
\threadsafe
*/
QDBusMessage QDBusAbstractInterface::callWithArgumentList(QDBus::CallMode mode,
const QString& method,
const QList<QVariant>& args)
{
Q_D(QDBusAbstractInterface);
QString m = method;
// split out the signature from the method
int pos = method.indexOf(QLatin1Char('.'));
if (pos != -1)
m.truncate(pos);
if (mode == QDBus::AutoDetect) {
// determine if this a sync or async call
mode = QDBus::Block;
const QMetaObject *mo = metaObject();
QByteArray match = m.toLatin1() + '(';
for (int i = staticMetaObject.methodCount(); i < mo->methodCount(); ++i) {
QMetaMethod mm = mo->method(i);
if (QByteArray(mm.signature()).startsWith(match)) {
// found a method with the same name as what we're looking for
// hopefully, nobody is overloading asynchronous and synchronous methods with
// the same name
QList<QByteArray> tags = QByteArray(mm.tag()).split(' ');
if (tags.contains("Q_NOREPLY"))
mode = QDBus::NoBlock;
break;
}
}
}
// qDebug() << "QDBusAbstractInterface" << "Service" << service() << "Path:" << path();
QDBusMessage msg = QDBusMessage::createMethodCall(service(), path(), interface(), m);
msg.setArguments(args);
QDBusMessage reply = d->connection.call(msg, mode);
d->lastError = reply; // will clear if reply isn't an error
// ensure that there is at least one element
if (reply.arguments().isEmpty())
reply << QVariant();
return reply;
}
示例15: lqtL_connect
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;
}