当前位置: 首页>>代码示例>>C++>>正文


C++ QMetaMethod::attributes方法代码示例

本文整理汇总了C++中QMetaMethod::attributes方法的典型用法代码示例。如果您正苦于以下问题:C++ QMetaMethod::attributes方法的具体用法?C++ QMetaMethod::attributes怎么用?C++ QMetaMethod::attributes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QMetaMethod的用法示例。


在下文中一共展示了QMetaMethod::attributes方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: generateInterfaceXml

static QString generateInterfaceXml(const QMetaObject *mo, int flags, int methodOffset, int propOffset)
{
    QString retval;

    // start with properties:
    if (flags & (QDBusConnection::ExportScriptableProperties |
                 QDBusConnection::ExportNonScriptableProperties)) {
        for (int i = propOffset; i < mo->propertyCount(); ++i) {
            static const char *accessvalues[] = {0, "read", "write", "readwrite"};

            QMetaProperty mp = mo->property(i);

            if (!((mp.isScriptable() && (flags & QDBusConnection::ExportScriptableProperties)) ||
                  (!mp.isScriptable() && (flags & QDBusConnection::ExportNonScriptableProperties))))
                continue;

            int access = 0;
            if (mp.isReadable())
                access |= 1;
            if (mp.isWritable())
                access |= 2;

            int typeId = qDBusNameToTypeId(mp.typeName());
            if (!typeId)
                continue;
            const char *signature = QDBusMetaType::typeToSignature(typeId);
            if (!signature)
                continue;

            retval += QString::fromLatin1("    <property name=\"%1\" type=\"%2\" access=\"%3\"")
                      .arg(QLatin1String(mp.name()))
                      .arg(QLatin1String(signature))
                      .arg(QLatin1String(accessvalues[access]));

            if (QDBusMetaType::signatureToType(signature) == QVariant::Invalid) {
                const char *typeName = QVariant::typeToName(QVariant::Type(typeId));
                retval += QString::fromLatin1(">\n      <annotation name=\"com.trolltech.QtDBus.QtTypeName\" value=\"%3\"/>\n    </property>\n")
                          .arg(typeNameToXml(typeName));
            } else {
                retval += QLatin1String("/>\n");
            }
        }
    }

    // now add methods:
    for (int i = methodOffset; i < mo->methodCount(); ++i) {
        QMetaMethod mm = mo->method(i);
        QByteArray signature = mm.signature();
        int paren = signature.indexOf('(');

        bool isSignal;
        if (mm.methodType() == QMetaMethod::Signal)
            // adding a signal
            isSignal = true;
        else if (mm.methodType() == QMetaMethod::Slot && mm.access() == QMetaMethod::Public)
            isSignal = false;
        else
            continue;           // neither signal nor public slot

        if (isSignal && !(flags & (QDBusConnection::ExportScriptableSignals |
                                   QDBusConnection::ExportNonScriptableSignals)))
            continue;           // we're not exporting any signals
        if (!isSignal && !(flags & (QDBusConnection::ExportScriptableSlots |
                                    QDBusConnection::ExportNonScriptableSlots)))
            continue;           // we're not exporting any slots

        QString xml = QString::fromLatin1("    <%1 name=\"%2\">\n")
                      .arg(isSignal ? QLatin1String("signal") : QLatin1String("method"))
                      .arg(QLatin1String(signature.left(paren)));

        // check the return type first
        int typeId = qDBusNameToTypeId(mm.typeName());
        if (typeId) {
            const char *typeName = QDBusMetaType::typeToSignature(typeId);
            if (typeName) {
                xml += QString::fromLatin1("      <arg type=\"%1\" direction=\"out\"/>\n")
                       .arg(typeNameToXml(typeName));

                // do we need to describe this argument?
                if (QDBusMetaType::signatureToType(typeName) == QVariant::Invalid)
                    xml += QString::fromLatin1("      <annotation name=\"com.trolltech.QtDBus.QtTypeName.Out0\" value=\"%1\"/>\n")
                           .arg(typeNameToXml(mm.typeName()));
            } else
                continue;
        }
        else if (*mm.typeName())
            continue;           // wasn't a valid type

        QList<QByteArray> names = mm.parameterNames();
        QList<int> types;
        int inputCount = qDBusParametersForMethod(mm, types);
        if (inputCount == -1)
            continue;           // invalid form
        if (isSignal && inputCount + 1 != types.count())
            continue;           // signal with output arguments?
        if (isSignal && types.at(inputCount) == QDBusMetaTypeId::message)
            continue;           // signal with QDBusMessage argument?
        if (isSignal && mm.attributes() & QMetaMethod::Cloned)
            continue;           // cloned signal?

//.........这里部分代码省略.........
开发者ID:muromec,项目名称:qtopia-ezx,代码行数:101,代码来源:qdbusxmlgenerator.cpp

示例2: qax_generateDocumentation

QString qax_generateDocumentation(QAxBase *that)
{
    that->metaObject();

    if (that->isNull())
	return QString();

    ITypeInfo *typeInfo = 0;
    IDispatch *dispatch = 0;
    that->queryInterface(IID_IDispatch, (void**)&dispatch);
    if (dispatch)
	dispatch->GetTypeInfo(0, LOCALE_SYSTEM_DEFAULT, &typeInfo);

    QString docu;
    QTextStream stream(&docu, QIODevice::WriteOnly);

    const QMetaObject *mo = that->metaObject();
    QString coClass  = QLatin1String(mo->classInfo(mo->indexOfClassInfo("CoClass")).value());

    stream << "<h1 align=center>" << coClass << " Reference</h1>" << endl;
    stream << "<p>The " << coClass << " COM object is a " << that->qObject()->metaObject()->className();
    stream << " with the CLSID " <<  that->control() << ".</p>" << endl;

    stream << "<h3>Interfaces</h3>" << endl;
    stream << "<ul>" << endl;
    const char *inter = 0;
    int interCount = 1;
    while ((inter = mo->classInfo(mo->indexOfClassInfo("Interface " + QByteArray::number(interCount))).value())) {
	stream << "<li>" << inter << endl;
	interCount++;
    }
    stream << "</ul>" << endl;

    stream << "<h3>Event Interfaces</h3>" << endl;
    stream << "<ul>" << endl;
    interCount = 1;  
    while ((inter = mo->classInfo(mo->indexOfClassInfo("Event Interface " + QByteArray::number(interCount))).value())) {
	stream << "<li>" << inter << endl;
	interCount++;
    }
    stream << "</ul>" << endl;

    QList<QString> methodDetails, propDetails;

    const int slotCount = mo->methodCount();
    if (slotCount) {
	stream << "<h2>Public Slots:</h2>" << endl;
	stream << "<ul>" << endl;

        int defArgCount = 0;
	for (int islot = mo->methodOffset(); islot < slotCount; ++islot) {
	    const QMetaMethod slot = mo->method(islot);
            if (slot.methodType() != QMetaMethod::Slot)
                continue;

            if (slot.attributes() & QMetaMethod::Cloned) {
                ++defArgCount;
                continue;
            }

	    QByteArray returntype(slot.typeName());
            if (returntype.isEmpty())
                returntype = "void";
            QByteArray prototype = namedPrototype(slot.parameterTypes(), slot.parameterNames(), defArgCount);
            QByteArray signature = slot.methodSignature();
	    QByteArray name = signature.left(signature.indexOf('('));
	    stream << "<li>" << returntype << " <a href=\"#" << name << "\"><b>" << name << "</b></a>" << prototype << ";</li>" << endl;
            
            prototype = namedPrototype(slot.parameterTypes(), slot.parameterNames());
	    QString detail = QString::fromLatin1("<h3><a name=") + QString::fromLatin1(name.constData()) + QLatin1String("></a>") +
                             QLatin1String(returntype.constData()) + QLatin1Char(' ') +
                             QLatin1String(name.constData()) + QLatin1Char(' ') +
                             QString::fromLatin1(prototype.constData()) + QLatin1String("<tt> [slot]</tt></h3>\n");
            prototype = namedPrototype(slot.parameterTypes(), QList<QByteArray>());
	    detail += docuFromName(typeInfo, QString::fromLatin1(name.constData()));
	    detail += QLatin1String("<p>Connect a signal to this slot:<pre>\n");
	    detail += QString::fromLatin1("\tQObject::connect(sender, SIGNAL(someSignal") + QString::fromLatin1(prototype.constData()) +
                      QLatin1String("), object, SLOT(") + QString::fromLatin1(name.constData()) +
                      QString::fromLatin1(prototype.constData()) + QLatin1String("));");
	    detail += QLatin1String("</pre>\n");

            if (1) {
                detail += QLatin1String("<p>Or call the function directly:<pre>\n");

                bool hasParams = slot.parameterTypes().count() != 0;
                if (hasParams)
                    detail += QLatin1String("\tQVariantList params = ...\n");
                detail += QLatin1String("\t");
                QByteArray functionToCall = "dynamicCall";
                if (returntype == "IDispatch*" || returntype == "IUnknown*") {
                    functionToCall = "querySubObject";
                    returntype = "QAxObject *";
                }
                if (returntype != "void")
                    detail += QLatin1String(returntype.constData()) + QLatin1String(" result = ");
                detail += QLatin1String("object->") + QLatin1String(functionToCall.constData()) +
                          QLatin1String("(\"" + name + prototype + '\"');
                if (hasParams)
                    detail += QLatin1String(", params");
                detail += QLatin1Char(')');
//.........这里部分代码省略.........
开发者ID:CodeDJ,项目名称:qt5-hidpi,代码行数:101,代码来源:qaxdump.cpp

示例3: classIDL


//.........这里部分代码省略.........
        bool ok = true;
        QByteArray type(convertTypes(property.typeName(), &ok));
        QByteArray name(replaceKeyword(property.name()));

        if (!ok)
            out << "\t/****** Property is of unsupported datatype" << endl;

        out << "\t\t[id(" << id << ')';
        if (!property.isWritable())
            out << ", readonly";
        if (isBindable && property.isScriptable(o))
            out << ", bindable";
        if (!property.isDesignable(o))
            out << ", nonbrowsable";
        if (isBindable)
            out << ", requestedit";
        if (defProp == QLatin1String(name))
            out << ", uidefault";
        out << "] " << type << ' ' << name << ';' << endl;

        if (!ok)
            out << "\t******/" << endl;
        ++id;
    }
    out << endl;
    out << "\tmethods:" << endl;
    int numDefArgs = 0;
    QByteArray outBuffer;
    for (i = methodoff; i < mo->methodCount(); ++i) {
        const QMetaMethod slot = mo->method(i);
        if (slot.access() != QMetaMethod::Public || slot.methodType() == QMetaMethod::Signal)
            continue;

        if (slot.attributes() & QMetaMethod::Cloned) {
            ++numDefArgs;
            continue;
        }
        if (!outBuffer.isEmpty()) {
            outBuffer = addDefaultArguments(outBuffer, numDefArgs);
            numDefArgs = 0;
            out << outBuffer;
            outBuffer = QByteArray();
        }

        QByteArray signature(slot.methodSignature());
        QByteArray name(signature.left(signature.indexOf('(')));
        if (i <= qtSlots && ignoreSlots(name))
            continue;

        signature.remove(0, name.length() + 1);
        signature.truncate(signature.length() - 1);
        name = renameOverloads(replaceKeyword(name));
        if (ignoreSlots(name))
            continue;

        QList<QByteArray> parameterTypes(slot.parameterTypes());
        QList<QByteArray> parameterNames(slot.parameterNames());

        bool ok = true;
        QByteArray type = slot.typeName();
        if (type.isEmpty())
            type = "void";
        else
            type = convertTypes(type, &ok);

        QByteArray ptype(prototype(parameterTypes, parameterNames, &ok));
开发者ID:RSATom,项目名称:Qt,代码行数:67,代码来源:qaxserver.cpp

示例4: init

/*!
	Initialized the ProxyBase Object. This needs to be run before any other functions are called.

	See the class description for an example of how to use this function

	@param funclist A list of strings to be used when searching for functions calls
	@param callbacklist A list of strings to used when searching for callbacks
	@param eventlist A list of strings to used when searching for events
 */
void ProxyBase::init(QStringList functionlist, QStringList callbacklist, QStringList eventlist)
{
	QMutexLocker locker(&qxt_d().mutex);
	//Initialize method counters
	int numfunctions = 1000;

	//clear old lists in case init() is run twice
	qxt_d().signalHash.clear();
	qxt_d().functions.clear();
	qxt_d().callbacks.clear();
	qxt_d().asyncfunctions.clear();

	//Get the meta object so we can see signals and slots
	const QMetaObject *meta = metaObject();
	//Get the number of methods
	int methods = meta->methodCount();

	//loop through all the methods
	for (int i = 0; i < methods; i++)
	{
		QMetaMethod method = meta->method(i);
		QString type = method.typeName();
		Signature sig(method.signature());

		// This checks to see if it's a cloned signal, and continues if it is...
		// Undocumented private API ftl!!!
		if (method.attributes() && 2)
			continue;

		switch (method.methodType())
		{
			case QMetaMethod::Signal:
				if (functionlist.contains(type))
				{
					//If a function begins with QObject*, char*, then its an asyn function
					if (sig.numArgs() >= 2 && sig.arg(0) == "QObject*" && (sig.arg(1) == "const char*" || sig.arg(1) == "char*"))
					{
						qxt_d().asyncfunctions << numfunctions; //add this function id to the list of async functions

						QVector<QString> args = sig.args(); //get the list of arguments
						//remove the first two arguments
						args.erase(args.begin());
						args.erase(args.begin());
						sig.setArgs(args); //update the argument list with the new list
					}
					Q_ASSERT(sig.validate());
					//connect the signal to a local event
					meta->connect(this, i, this, numfunctions, Qt::DirectConnection);
					qxt_d().functions[numfunctions] = sig;
					qxt_d().functiontypes[numfunctions] = method.typeName();
					numfunctions++;
				}
				else if (eventlist.contains(type))
				{
					Q_ASSERT(sig.validate());
					qxt_d().signalHash[i] = sig;
				}
				//if its not one of the two, we don't care about it
				break;

			case QMetaMethod::Slot:
				if (callbacklist.contains(type))
				{
					Q_ASSERT(sig.validate());
					qxt_d().callbacks[i] = sig;
				}
				break;

			default:
				//We don't really care about other types of methods
				break;
		}
	}
}
开发者ID:SiteView,项目名称:QtRPC2,代码行数:83,代码来源:proxybase.cpp

示例5: connect

bool QObject::connect(const QObject *sender, const QMetaMethod &signalMetaMethod, const QObject *receiver, 
            const QMetaMethod &slotMetaMethod, Qt::ConnectionType type)
{
   if (sender == 0) {
       qWarning("QObject::connect() Can not connect as sender is null");
       return false;
   }

   if (receiver == 0) {
       qWarning("QObject::connect() Can not connect as receiver is null");
       return false;
   }
   // get signal name
   const char *senderClass   = sender->metaObject()->className();
   const char *receiverClass = receiver->metaObject()->className();

   const char *signalName = signalMetaMethod.signature();
   const char *slotName   = slotMetaMethod.signature();

   if (! signalName || signalName[0] == 0)  {
      qWarning("%s%s%s%s%s", "QObject::connect() ", senderClass, "::<Invalid Signal> ",
               " Unable to connect to receiver in ", receiverClass);

      return false;
   }

   if (! slotName || slotName[0] == 0 )  {
      qWarning("%s%s%s%s%s%s%s", "QObject::connect() ", senderClass, "::", signalName,
                        " Unable to connect to receiver in ", receiverClass, "::<Invalid Slot>");
      return false;
   }

   // is signalMethod a signal
   if (signalMetaMethod.methodType() != QMetaMethod::Signal) {
      qWarning("%s%s%s%s%s", "QObject::connect() ", senderClass, "::", signalName,
                        ": Is not a valid signal");
      return false;
   }

   // is slotMethod a clone, then there is a defualt parameter
   if (slotMetaMethod.attributes() & QMetaMethod::Cloned) {
      qWarning("%s%s%s%s%s", "QObject::connect() ", receiverClass, "::", slotName,
                        ": Unable to connect to a slot with a default parameter");
      return false;
   }

   // test arguments
   bool err = false;
   QList<QByteArray> typesSignal = signalMetaMethod.parameterTypes();
   QList<QByteArray> typesSlot   = slotMetaMethod.parameterTypes();

   if (typesSignal.count() < typesSlot.count() )  {
      err = true;

   } else {

      for(int index = 0; index != typesSlot.count(); ++index)   {

         if (typesSignal.at(index) != typesSlot.at(index)) {
            // unable to test if typeDefs are used
            err = true;
            break;
         }

      }
   }

   if (err) {
      qWarning("%s%s%s%s%s%s%s%s", "QObject::connect() ", senderClass, "::", signalName,
                        ": Incompatible signal/slot arguments ", receiverClass, "::", slotName);
      return false;
   }

   //
   if (type == Qt::AutoCompatConnection) {
       type = Qt::AutoConnection;
   }

   //
   const BentoAbstract *signalMethod_Bento = signalMetaMethod.getBentoBox();
   const BentoAbstract *slotMethod_Bento   = slotMetaMethod.getBentoBox();

   if (! signalMethod_Bento) {
      qWarning("%s%s%s%s%s", "QObject::connect() ", senderClass, "::", signalName,
                               " Unable to locate the requested signal, verify connect arguments and signal declaration");
      return false;
   }

   if (! slotMethod_Bento) {
      qWarning("%s%s%s%s%s", "QObject::connect() ", receiverClass, "::", slotName,
                               " Unable to locate the requested slot, verify connect arguments and slot declaration");
      return false;
   }

   std::unique_lock<std::mutex> senderLock{sender->m_mutex_ToReceiver};
   std::unique_lock<std::mutex> receiverLock{receiver->m_mutex_FromSender};

   if (type & Qt::UniqueConnection) {
      // user passed enum to ensure the connection is not added twice

//.........这里部分代码省略.........
开发者ID:wpbest,项目名称:copperspice,代码行数:101,代码来源:qobject.cpp


注:本文中的QMetaMethod::attributes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。