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


C++ QVariant::userType方法代码示例

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


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

示例1: streamDebug

static void streamDebug(QDebug dbg, const QVariant &v)
{

    if((uint)v.userType() == JOBJECTWRAPPER_TYPE) {
        const JObjectWrapper wrapper = v.value<JObjectWrapper>();
        JNIEnv *env = qtjambi_current_environment();
        StaticCache *sc = StaticCache::instance();
        sc->resolveObject();
        jobject java_object =  wrapper.object;
        dbg << qtjambi_to_qstring(env, static_cast<jstring>(env->CallObjectMethod(java_object, sc->Object.toString)));
        return;
    }
    else if (QtJambiVariant::getLastHandler()) {
        QtJambiVariant::getLastHandler()->debugStream(dbg, v);
        return;
    }
    else if (qcoreVariantHandler()) {
        qcoreVariantHandler()->debugStream(dbg, v);
        return;
    }
}
开发者ID:Smarre,项目名称:qtjambi,代码行数:21,代码来源:qtjambivariant.cpp

示例2: testTearDown

void ScriptedTutorialTest::testTearDown() {
    QSKIP("Skipped until tearDown argument is set again to scripting::ScriptedTutorial*", SkipAll);

    ScriptedTutorial scriptedTutorial(mTemporaryFile->fileName());

    //ScriptedTutorial* must be registered in order to be used with QSignalSpy.
    //The name must contain the namespace, as it needs the full name used in the
    //signal (and the signal has to be declared using the full namespace so the
    //spied argument can be converted using qvariant_cast).
    int scriptedTutorialStarType =
        qRegisterMetaType<ScriptedTutorial*>("scripting::ScriptedTutorial*");
    QSignalSpy tearDownSpy(&scriptedTutorial,
                           SIGNAL(tearDown(scripting::ScriptedTutorial*)));

    scriptedTutorial.tearDown();

    QCOMPARE(tearDownSpy.count(), 1);
    QVariant argument = tearDownSpy.at(0).at(0);
    QCOMPARE(argument.userType(), scriptedTutorialStarType);
    QCOMPARE(qvariant_cast<ScriptedTutorial*>(argument), &scriptedTutorial);
}
开发者ID:KDE,项目名称:ktutorial,代码行数:21,代码来源:ScriptedTutorialTest.cpp

示例3: property_helper

SValue SValue::property_helper(const QString &name)
{
	qfLogFuncFrame() << name;
	SValue ret;
	QVariant v = d->value.toMap().value(name);
	if(v.userType() == qMetaTypeId<SValue>()) {
		/// je to v pohode vracim object, ktery jiz existuje
		ret = qvariant_cast<SValue>(v);
	}
	else {
		if(v.isValid()) {
			/// objekt existuje, ale neni SValue, tak ji z nej vyrob
			ret.setValue(v);
		}
		else {
			/// objekt neexistuje
		}
		setProperty(name, ret);
	}
	return ret;
}
开发者ID:Nechanicky,项目名称:quickbox,代码行数:21,代码来源:svalue.cpp

示例4: qAppendVariantToMessage

static bool qAppendVariantToMessage(DBusMessageIter *it, const QDBusType &type,
                                    const QVariant &var)
{
    Q_UNUSED(type);             // type is 'v'

    QVariant arg = var;
    if (var.userType() == QDBusTypeHelper<QVariant>::id())
        arg = QDBusTypeHelper<QVariant>::fromVariant(var); // extract the inner variant
    
    QDBusType t = QDBusType::guessFromVariant(arg);
    if (!t.isValid())
        return false;
    
    // now add this variant
    DBusMessageIter sub;
    dbus_message_iter_open_container(it, DBUS_TYPE_VARIANT, t.dbusSignature(), &sub);
    qVariantToIteratorInternal(&sub, arg, t);
    dbus_message_iter_close_container(it, &sub);

    return true;                // success
}
开发者ID:freedesktop-unofficial-mirror,项目名称:dbus__dbus-qt3,代码行数:21,代码来源:qdbusmarshall.cpp

示例5: QVariant

static int
qstringlist_new(lua_State *L)
{
  QStringList l;
  if (! lua_isnone(L, 1))
    {
      luaL_checktype(L, 1, LUA_TTABLE);
      int n = lua_objlen(L, 1);
      for (int i=1; i<=n; i++)
        {
          lua_rawgeti(L, 1, i);
          QVariant v = luaQ_toqvariant(L, -1, QMetaType::QString);
          if (v.userType() != QMetaType::QString)
            luaL_error(L, "table element cannot be converted to a QString");
          l += v.toString();
          lua_pop(L, 1);
        }
    }
  luaQ_pushqt(L, QVariant(l));
  return 1;
}
开发者ID:elq,项目名称:torch5,代码行数:21,代码来源:qtluautils.cpp

示例6: toUserString

QString ConversionUtil::toUserString(const QVariant &variant) {

    if (!variant.isValid()) {
        return "(not set)";
    }

    switch (variant.type()) {
        case QVariant::Bool:
            return variant.toBool() ? "true" : "false";
        case QVariant::Int:
            return QString::number(variant.toInt());
        case QVariant::Double:
            return QString::number(variant.toDouble());
        case QVariant::String: {
            QString string = variant.toString();
            return string.isEmpty() ? "(empty string)" : string;
        }
        case QVariant::StringList:
            return variant.toStringList().join("\n");
        case QVariant::DateTime:
            return variant.toDateTime().toString();
        case QVariant::Map: {
            QStringList stringList;
            QVariantMap map = variant.toMap();
            for (const QString &key : map.keys()) {
                stringList << QString("%1: %2").arg(jsString(key), toUserString(map[key]));
            }
            return stringList.isEmpty() ? "(empty)" : stringList.join("\n");
        }
        case QVariant::UserType: {
            MetaTypeRegistry::UserStringConverters converters =
                    MetaTypeRegistry::userStringConverters(QMetaType::typeName(variant.userType()));
            if (converters.typeToUserStringConverter) {
                return converters.typeToUserStringConverter(variant);
            }
        }   // fall-through
        default:
            return "(unknown type)";
    }
}
开发者ID:Auroness,项目名称:PlainText,代码行数:40,代码来源:conversionutil.cpp

示例7: engineTypes

void tst_qdeclarativelistreference::engineTypes()
{
    QDeclarativeEngine engine;
    QDeclarativeComponent component(&engine, TEST_FILE("engineTypes.qml"));

    QObject *o = component.create();
    QVERIFY(o);

    QDeclarativeProperty p1(o, QLatin1String("myList"));
    QVERIFY(p1.propertyTypeCategory() == QDeclarativeProperty::Normal);

    QDeclarativeProperty p2(o, QLatin1String("myList"), engine.rootContext());
    QVERIFY(p2.propertyTypeCategory() == QDeclarativeProperty::List);
    QVariant v = p2.read();
    QVERIFY(v.userType() == qMetaTypeId<QDeclarativeListReference>());
    QDeclarativeListReference ref = qvariant_cast<QDeclarativeListReference>(v);
    QVERIFY(ref.count() == 2);
    QVERIFY(ref.listElementType());
    QVERIFY(ref.listElementType() != &QObject::staticMetaObject);

    delete o;
}
开发者ID:husninazer,项目名称:qt,代码行数:22,代码来源:tst_qdeclarativelistreference.cpp

示例8:

void
 DBusIf::signal(QString path, QString interface, QString method,
		QVariant v)
{
	QDBusMessage msg = QDBusMessage::createSignal(path, interface, method);

    // unbox the QVariant-QJSValue to fix the Qt 5.4 QML -> C++ QVariant issues
    if (v.userType() == qMetaTypeId<QJSValue>()) {
        v = v.value<QJSValue>().toVariant();
    }

	if (v.type() == QVariant::List) {
		QVariantList l = v.value < QVariantList > ();
		for (int i = 0; i < l.size(); i++) {
			msg << l[i]; }
	} else
		msg << v;
	QDBusConnection::sessionBus().send(msg);
#if 0
	qDebug() << v;
#endif
}
开发者ID:GENIVI,项目名称:navigation-application,代码行数:22,代码来源:dbusif.cpp

示例9:

bool Nuria::Serializer::readField (void *object, Nuria::MetaField &field, QVariantMap &data) {
	QVariant value = field.read (object);
	QString name = QString::fromLatin1 (field.name ());
	
	if (isAllowedType (value.userType ()) ||
	    this->d->additionalTypes.contains (field.typeName ())) {
		data.insert (name, value);
		return true;
	}
	
	bool ignore = false;
	if (fieldToVariant (value, ignore)) {
		
		if (!ignore) {
			data.insert (name, value);
		}
		
		return true;
	}
	
	return false;
}
开发者ID:delgor,项目名称:Core,代码行数:22,代码来源:serializer.cpp

示例10: readMetadata

QVariantHash GeoIPDatabase::readMetadata() const
{
    const char *ptr = reinterpret_cast<const char *>(m_data);
    quint32 size = m_size;
    if (m_size > MAX_METADATA_SIZE) {
        ptr += m_size - MAX_METADATA_SIZE;
        size = MAX_METADATA_SIZE;
    }

    const QByteArray data = QByteArray::fromRawData(ptr, size);
    int index = data.lastIndexOf(METADATA_BEGIN_MARK);
    if (index >= 0) {
        if (m_size > MAX_METADATA_SIZE)
            index += (m_size - MAX_METADATA_SIZE); // from begin of all data
        quint32 offset = static_cast<quint32>(index + strlen(METADATA_BEGIN_MARK));
        QVariant metadata = readDataField(offset);
        if (metadata.userType() == QMetaType::QVariantHash)
            return metadata.toHash();
    }

    return QVariantHash();
}
开发者ID:zywo,项目名称:qBittorrent,代码行数:22,代码来源:geoipdatabase.cpp

示例11: engineTypes

void tst_qqmllistreference::engineTypes()
{
    QQmlEngine engine;
    QQmlComponent component(&engine, testFileUrl("engineTypes.qml"));

    QObject *o = component.create();
    QVERIFY(o);

    QQmlProperty p1(o, QLatin1String("myList"));
    QVERIFY(p1.propertyTypeCategory() == QQmlProperty::List);

    QQmlProperty p2(o, QLatin1String("myList"), engine.rootContext());
    QVERIFY(p2.propertyTypeCategory() == QQmlProperty::List);
    QVariant v = p2.read();
    QVERIFY(v.userType() == qMetaTypeId<QQmlListReference>());
    QQmlListReference ref = qvariant_cast<QQmlListReference>(v);
    QVERIFY(ref.count() == 2);
    QVERIFY(ref.listElementType());
    QVERIFY(ref.listElementType() != &QObject::staticMetaObject);

    delete o;
}
开发者ID:ghjinlei,项目名称:qt5,代码行数:22,代码来源:tst_qqmllistreference.cpp

示例12: variantIsTrue

bool Grantlee::variantIsTrue( const QVariant &variant )
{

  if ( !variant.isValid() )
    return false;
  switch ( variant.userType() ) {
  case QVariant::Bool: {
    return variant.toBool();
  }
  case QVariant::Int: {
    return ( variant.toInt() > 0 );
  }
  case QVariant::Double: {
    return ( variant.toDouble() > 0 );
  }
  case QMetaType::Float: {
    return ( variant.toFloat() > 0 );
  }
  case QMetaType::QObjectStar: {
    QObject *obj = variant.value<QObject *>();
    if ( !obj )
      return false;

    if ( obj->property( "__true__" ).isValid() ) {
      return obj->property( "__true__" ).toBool();
    }
    return true;
  }
  case QVariant::List: {
    return ( variant.toList().size() > 0 );
  }
  case QVariant::Hash: {
    return ( variant.toHash().size() > 0 );
  }
  }

  return !getSafeString( variant ).get().isEmpty();
}
开发者ID:hicknhack-software,项目名称:Qt-Grantlee,代码行数:38,代码来源:util.cpp

示例13: indexHasIncidents

bool QTestFunction::indexHasIncidents(const QModelIndex &function, IncidentType type)
{
    if (!function.isValid())
        return false;
    const QAbstractItemModel *m = function.model();
    if (!m->hasChildren(function))
        return false;

    const int rows = m->rowCount(function);
    for (int row = 0; row < rows; ++row) {
        const QModelIndex child = m->index(row, 0, function);

        QVariant tag = child.data(Qt::UserRole + 1);
        if (tag.type() != QVariant::UserType
            || tag.userType() != qMetaTypeId<QTestFunction::IncidentType>())
            continue;

        if (tag.value<QTestFunction::IncidentType>() == type)
            return true;
    }

    return false;
}
开发者ID:anchowee,项目名称:QtCreator,代码行数:23,代码来源:qtestlibplugin.cpp

示例14: valueForName

QVariant ArgumentsEditor::valueForName(const QString &name,
                                       const QVariant &originalValue,
                                       bool *changed) const
{
    QVariant val;

    *changed = false;

    //Handle string arrays specially
    if (isVariantStringArray(originalValue)) {
        ApiArray array = originalValue.value<ApiArray>();
        return arrayFromEditor(array, changed);
    }

    if (!isVariantEditable(originalValue)) {
        return originalValue;
    }

    for (int topRow = 0; topRow < m_model->rowCount(); ++topRow) {
        QModelIndex nameIdx = m_model->index(topRow, 0, QModelIndex());
        QString argName = nameIdx.data().toString();
        /* we display shaders in a separate widget so
         * the ordering might be different */
        if (argName == name) {
            if (originalValue.userType() == QMetaType::type("ApiArray")) {
                ApiArray array = originalValue.value<ApiArray>();
                val = arrayFromIndex(nameIdx, array, changed);
            } else {
                QModelIndex valIdx = m_model->index(topRow, 1, QModelIndex());
                val = valIdx.data();
                if (val != originalValue)
                    *changed = true;
            }
        }
    }
    return val;
}
开发者ID:Acidburn0zzz,项目名称:apitrace,代码行数:37,代码来源:argumentseditor.cpp

示例15: Compare

int MultiSortFilterProxy::Compare(const QVariant& left,
                                  const QVariant& right) const {
  // Copied from the QSortFilterProxyModel::lessThan implementation, but returns
  // -1, 0 or 1 instead of true or false.
  switch (left.userType()) {
    case QVariant::Invalid:
      return (right.type() != QVariant::Invalid) ? -1 : 0;
    case QVariant::Int:
      return DoCompare(left.toInt(), right.toInt());
    case QVariant::UInt:
      return DoCompare(left.toUInt(), right.toUInt());
    case QVariant::LongLong:
      return DoCompare(left.toLongLong(), right.toLongLong());
    case QVariant::ULongLong:
      return DoCompare(left.toULongLong(), right.toULongLong());
    case QMetaType::Float:
      return DoCompare(left.toFloat(), right.toFloat());
    case QVariant::Double:
      return DoCompare(left.toDouble(), right.toDouble());
    case QVariant::Char:
      return DoCompare(left.toChar(), right.toChar());
    case QVariant::Date:
      return DoCompare(left.toDate(), right.toDate());
    case QVariant::Time:
      return DoCompare(left.toTime(), right.toTime());
    case QVariant::DateTime:
      return DoCompare(left.toDateTime(), right.toDateTime());
    case QVariant::String:
    default:
      if (isSortLocaleAware())
        return left.toString().localeAwareCompare(right.toString());
      else
        return left.toString().compare(right.toString(), sortCaseSensitivity());
  }

  return 0;
}
开发者ID:Aceler,项目名称:Clementine,代码行数:37,代码来源:multisortfilterproxy.cpp


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