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


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

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


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

示例1: qgsVariantLessThan

bool qgsVariantLessThan( const QVariant& lhs, const QVariant& rhs )
{
  switch ( lhs.type() )
  {
    case QVariant::Int:
      return lhs.toInt() < rhs.toInt();
    case QVariant::UInt:
      return lhs.toUInt() < rhs.toUInt();
    case QVariant::LongLong:
      return lhs.toLongLong() < rhs.toLongLong();
    case QVariant::ULongLong:
      return lhs.toULongLong() < rhs.toULongLong();
    case QVariant::Double:
      return lhs.toDouble() < rhs.toDouble();
    case QVariant::Char:
      return lhs.toChar() < rhs.toChar();
    case QVariant::Date:
      return lhs.toDate() < rhs.toDate();
    case QVariant::Time:
      return lhs.toTime() < rhs.toTime();
    case QVariant::DateTime:
      return lhs.toDateTime() < rhs.toDateTime();
    default:
      return QString::localeAwareCompare( lhs.toString(), rhs.toString() ) < 0;
  }
}
开发者ID:dakcarto,项目名称:QGIS-Auth,代码行数:26,代码来源:qgis.cpp

示例2: method_valueOf

QScriptValueImpl Variant::method_valueOf(QScriptContextPrivate *context, QScriptEnginePrivate *eng, QScriptClassInfo *classInfo)
{
    if (Instance *instance = Instance::get(context->thisObject(), classInfo)) {
        QVariant v = instance->value;
        switch (v.type ()) {
        case QVariant::Invalid:
            return eng->undefinedValue();
        case QVariant::String:
            return (QScriptValueImpl(eng, v.toString()));

        case QVariant::Int:
            return (QScriptValueImpl(v.toInt()));

        case QVariant::Bool:
            return (QScriptValueImpl(v.toBool()));

        case QVariant::Double:
            return (QScriptValueImpl(v.toDouble())); // ### hmmm

        case QVariant::Char:
            return (QScriptValueImpl(v.toChar().unicode()));

        case QVariant::UInt:
            return (QScriptValueImpl(v.toUInt()));

        default:
            return context->thisObject();
        } // switch
    }
    return context->thisObject();
}
开发者ID:IamHokum,项目名称:qt-solutions,代码行数:31,代码来源:qscriptextvariant.cpp

示例3: push_qvariant

void lua::push_qvariant(lua_State* const state, const QVariant& value)
{
    switch (value.userType()) {
        case QVariant::Invalid:
            lua::push(state, lua::value::nil);
            break;
        case QVariant::Bool:
            lua::push(state, value.toBool());
            break;
        case QVariant::Char:
            lua::push(state, value.toChar());
            break;
        case QVariant::Int:
        {
            lua::push(state, value.toInt());
            break;
        }
        case QVariant::Double:
        case QVariant::UInt:
            lua::push(state, value.toDouble());
            break;
        case QVariant::String:
            lua::push(state, value.toString());
            break;
        case QVariant::Hash:
        {
            auto hash = value.toHash();

            auto table = lua::push(state, lua::value::table);
            for (auto i = hash.begin(); i != hash.end(); ++i) {
                lua::table::set(table, i.key(), i.value());
            }

            break;
        }
        case QVariant::StringList:
        {
            auto list = value.toStringList();

            auto table = lua::push(state, lua::value::table);
            for (int i = 0; i < list.size(); ++i) {
                lua::table::set(table, i + 1, list[i]);
            }

            break;
        }
        default:
        {
            auto converter = qvariant_push_handler.find(value.userType());
            if (converter != qvariant_push_handler.end()) {
                converter->second(state, value);
            } else {
                throw std::logic_error(std::string("No handler exists to push QVariant type: ") + value.typeName());
            }
        }
    }
}
开发者ID:azraelly,项目名称:luacxx,代码行数:57,代码来源:QVariant.cpp

示例4: valueToString

QString AsteriskManager::valueToString(QVariant value)
{
  switch (value.type()) {
  case QVariant::Char:
    return value.toChar() == 1 ? "true" : "false";
  default:
    return value.toString();
  }
}
开发者ID:dwatson78,项目名称:Qt-Asterisk-Desktop,代码行数:9,代码来源:asteriskmanager.cpp

示例5: qHash

uint qHash(const QVariant &var)
{
    if (!var.isValid() || var.isNull())
        return -1;

    switch (var.type())
    {
    case QVariant::Int:
        return qHash( var.toInt() );
    case QVariant::UInt:
        return qHash( var.toUInt() );
    case QVariant::Bool:
        return qHash( var.toUInt() );
    case QVariant::Double:
        return qHash( var.toUInt() );
    case QVariant::LongLong:
        return qHash( var.toLongLong() );
    case QVariant::ULongLong:
        return qHash( var.toULongLong() );
    case QVariant::String:
        return qHash( var.toString() );
    case QVariant::Char:
        return qHash( var.toChar() );
    case QVariant::StringList:
        return qHash( var.toString() );
    case QVariant::ByteArray:
        return qHash( var.toByteArray() );
    case QVariant::Date:
    case QVariant::Time:
    case QVariant::DateTime:
    case QVariant::Url:
    case QVariant::Locale:
    case QVariant::RegExp:
        return qHash( var.toString() );
    case QVariant::Map:
    case QVariant::List:
    case QVariant::BitArray:
    case QVariant::Size:
    case QVariant::SizeF:
    case QVariant::Rect:
    case QVariant::LineF:
    case QVariant::Line:
    case QVariant::RectF:
    case QVariant::Point:
    case QVariant::UserType:
    case QVariant::Invalid:
    default:
        Q_ASSERT(false);
    }

    // could not generate a hash for the given variant
    Q_ASSERT(false);
    return 0;
}
开发者ID:lbproductions,项目名称:psconvert,代码行数:54,代码来源:dataaccessobject.cpp

示例6: 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

示例7: getCsvSeparator

char AppSettings::getCsvSeparator (void)
{
  QVariant var = m_Settings.value(SETTINGNAME_CSV_SEPARATOR);
  if (var.canConvert(QVariant::Char))
  {
    char c = var.toChar().toAscii();

    if (ExporterSinkCsv::isAllowedSeparator(c))
      return c;
    else
      this->setCsvSeparator(ExporterSinkCsv::defaultSeparator());
  }

  return ExporterSinkCsv::defaultSeparator();
}
开发者ID:berezhko,项目名称:gpsrecorder-n900,代码行数:15,代码来源:AppSettings.cpp

示例8:

bool ResultsTree::GroupSortProxyModel::QVariantCompare::operator() (QVariant l, QVariant r)
{
	// CODE COPIED FROM QSortFilterProxyModel::lessThan
	
	switch (l.userType()) {
		case QVariant::Invalid:
			return (r.type() != QVariant::Invalid);
		case QVariant::Int:
			return l.toInt() < r.toInt();
		case QVariant::UInt:
			return l.toUInt() < r.toUInt();
		case QVariant::LongLong:
			return l.toLongLong() < r.toLongLong();
		case QVariant::ULongLong:
			return l.toULongLong() < r.toULongLong();
		case QMetaType::Float:
			return l.toFloat() < r.toFloat();
		case QVariant::Double:
			return l.toDouble() < r.toDouble();
		case QVariant::Char:
			return l.toChar() < r.toChar();
		case QVariant::Date:
			return l.toDate() < r.toDate();
		case QVariant::Time:
			return l.toTime() < r.toTime();
		case QVariant::DateTime:
			return l.toDateTime() < r.toDateTime();
		case QVariant::String:
		default:
			//if (d->sort_localeaware)
				return l.toString().localeAwareCompare(r.toString()) < 0;
			/*else
				return l.toString().compare(r.toString(), d->sort_casesensitivity) < 0;*/
	}
	return false;
}
开发者ID:OpenOrienteering,项目名称:cupcalculator,代码行数:36,代码来源:resultList.cpp

示例9: variantToKey

Qt::Key QtUiTest::variantToKey(const QVariant &keyValue)
{
    Qt::Key key = (Qt::Key)0;
    switch(keyValue.type()) {
    default:
        key = (Qt::Key)keyValue.toInt();
        break;
    case QVariant::Char:
        key = QtUiTest::asciiToKey(keyValue.toChar().toAscii());
        break;
    case QVariant::String:
        if (keyValue.toString().length() == 1)
            key = QtUiTest::asciiToKey(keyValue.toString()[0].toAscii());
        break;
    }
    return key;
}
开发者ID:qtproject,项目名称:playground-qtsystemtest,代码行数:17,代码来源:qasciikey.cpp

示例10: chooseAction

void MergeTool::chooseAction()
{
    m_merging = (m_mergeType == NormalMerge);
    if (m_merging)
        return;
    QMessageBox msgBox;
    msgBox.setWindowTitle(tr("Merge Conflict"));
    msgBox.setIcon(QMessageBox::Question);
    msgBox.setStandardButtons(QMessageBox::Abort);
    msgBox.setText(tr("%1 merge conflict for \"%2\"\nLocal: %3\nRemote: %4")
                   .arg(mergeTypeName())
                   .arg(m_fileName)
                   .arg(stateName(m_localState, m_localInfo))
                   .arg(stateName(m_remoteState, m_remoteInfo))
                   );
    switch (m_mergeType) {
    case SubmoduleMerge:
    case SymbolicLinkMerge:
        addButton(&msgBox, tr("&Local"), 'l');
        addButton(&msgBox, tr("&Remote"), 'r');
        break;
    case DeletedMerge:
        if (m_localState == CreatedState || m_remoteState == CreatedState)
            addButton(&msgBox, tr("&Created"), 'c');
        else
            addButton(&msgBox, tr("&Modified"), 'm');
        addButton(&msgBox, tr("&Deleted"), 'd');
        break;
    default:
        break;
    }

    msgBox.exec();
    QByteArray ba;
    QVariant key;
    QAbstractButton *button = msgBox.clickedButton();
    if (button)
        key = button->property("key");
    // either the message box was closed without clicking anything, or abort was clicked
    if (!key.isValid())
        key = QVariant(QLatin1Char('a')); // abort
    ba.append(key.toChar().toLatin1());
    ba.append('\n');
    m_process->write(ba);
    m_process->waitForBytesWritten();
}
开发者ID:DuinoDu,项目名称:qt-creator,代码行数:46,代码来源:mergetool.cpp

示例11: variantToScriptValue

QScriptValue ScriptToolbox::variantToScriptValue(QScriptEngine * engine, QVariant var)
{
  if(var.isNull())
    return engine->nullValue();

  switch(var.type())
  {
    case QVariant::Invalid:
      return engine->nullValue();
    case QVariant::Bool:
      return QScriptValue(engine, var.toBool());
    case QVariant::Int:
      return QScriptValue(engine, var.toInt());
    case QVariant::UInt:
      return QScriptValue(engine, var.toUInt());
    case QVariant::Double:
      return QScriptValue(engine, var.toDouble());
    case QVariant::Char:
      return QScriptValue(engine, var.toChar().unicode());
    case QVariant::String:
      return QScriptValue(engine, var.toString());
    case QVariant::LongLong:
      return QScriptValue(engine, qsreal(var.toLongLong()));
    case QVariant::ULongLong:
      return QScriptValue(engine, qsreal(var.toULongLong()));
    case QVariant::Date:
    case QVariant::Time:
    case QVariant::DateTime:
      return engine->newDate(var.toDateTime());
    case QVariant::RegExp:
      return engine->newRegExp(var.toRegExp());
/*
 * Would be ideal to have these as well but I don't know if they are really necessary
    case QVariant::StringList:
    case QVariant::List:

    case QVariant::Map:
*/
    default:
      return engine->newVariant(var);
  }

  // If we are not doing an explicity conversion just pass the variant back
  // and see what happens
  return engine->newVariant(var);
}
开发者ID:,项目名称:,代码行数:46,代码来源:

示例12: insertNotEmpty

void AsteriskManager::insertNotEmpty(QVariantMap *headers, QString key, QVariant value)
{
  bool isEmpty = false;

  switch (value.type()) {
  case QMetaType::Int:
    isEmpty = value.toChar() == -1;
    break;
  case QMetaType::UInt:
    isEmpty = value.toUInt() == 0;
    break;
  default:
    isEmpty = value.isNull();
    break;
  }

  if (!isEmpty)
    headers->insert(key, value);
}
开发者ID:dwatson78,项目名称:Qt-Asterisk-Desktop,代码行数:19,代码来源:asteriskmanager.cpp

示例13: matches

bool QValueFilter::matches(const QVariant & value, int type) const
{
    Qt::CaseSensitivity s;
    Qt::MatchFlag mf;
    int t = type;
    if (t == -1){
        t = value.type();
    }
    switch(t)
    {
    case QVariant::Char:
        return value.toChar() == property("value").toChar();
    case QVariant::Date:
        return value.toDate() == property("value").toDate();
    case QVariant::DateTime:
        return value.toDateTime() == property("value").toDateTime();
    case QVariant::Double:
        return value.toDouble() == property("value").toDouble();
    case QVariant::Int:
        return value.toInt() == property("value").toInt();
    case QVariant::LongLong:
        return value.toLongLong() == property("value").toLongLong();
    case QVariant::String:
        s = static_cast<Qt::CaseSensitivity>(property("caseSensitivity", Qt::CaseInsensitive).toInt());
        mf = static_cast<Qt::MatchFlag>(property("matchFlag", Qt::MatchStartsWith).toInt());
        if (mf == Qt::MatchContains){
            return value.toString().contains(property("value").toString(), s);
        } else if (mf == Qt::MatchEndsWith){
            return QString::compare(value.toString().right(property("value").toString().length()), property("value").toString(), s) == 0;
        }
        return QString::compare(value.toString().left(property("value").toString().length()), property("value").toString(), s) == 0;
    case QVariant::Time:
        return value.toTime() == property("value").toTime();
    case QVariant::UInt:
        return value.toUInt() == property("value").toUInt();
    case QVariant::ULongLong:
        return value.toULongLong() == property("value").toULongLong();
    default:
        return value == property("value");
    }
    return false;
}
开发者ID:lit-uriy,项目名称:QAdvancedItemViews,代码行数:42,代码来源:qvaluefilter.cpp

示例14: _push

static void _push(lua_State *L, const QVariant & v)
{
    switch( v.type() )
    {
    case QVariant::Invalid:
        lua_pushnil( L );
        break;
    case QVariant::Bool:
        lua_pushboolean( L, v.toBool() );
        break;
    case QVariant::Int:
        lua_pushnumber( L, v.toInt() );
        break;
    case QVariant::Double:
        lua_pushnumber( L, v.toDouble() );
        break;
    case QVariant::LongLong:
        lua_pushnumber( L, v.toLongLong() );
        break;
    case QVariant::ULongLong:
        lua_pushnumber( L, (double)(quint32)v.toULongLong() );
        break;
    case QVariant::UInt:
        lua_pushnumber( L, v.toUInt() );
        break;
    case QVariant::Char:
        lua_pushnumber( L, v.toChar().unicode() );
        break;
    case QVariant::ByteArray:
        lua_pushstring( L, v.toByteArray() );
        break;
    case QVariant::String:
        lua_pushstring( L, v.toString().toLatin1() );
        break;
    default:
        lua_pushnil( L );
        break;
    }
}
开发者ID:Wushaowei001,项目名称:NAF,代码行数:39,代码来源:QtValue.cpp

示例15: json_file_generate

bool json_file_generate (QTextStream &res, const QVariant &val, int indent) {
    switch (val.type()) {
    case QVariant::Invalid: res << "null"; break;
    case QVariant::Bool: res << (val.toBool() ? "true" : "false"); break;
    case QVariant::Char: res << Json::quote(QString(val.toChar())).toUtf8(); break;
    case QVariant::Double: res << QString::number(val.toDouble()).toLatin1(); break; //CHECKME: is '.' always '.'?
    case QVariant::Int: res << QString::number(val.toInt()).toLatin1(); break;
    case QVariant::String: res << Json::quote(val.toString()).toUtf8(); break;
    case QVariant::UInt: res << QString::number(val.toUInt()).toLatin1(); break;
    case QVariant::ULongLong: res << QString::number(val.toULongLong()).toLatin1(); break;
    case QVariant::Map: {
        //for (int c = indent; c > 0; c--) res << ' ';
        res << "{";
        indent++; bool comma = false;
        QVariantMap m(val.toMap());
        QVariantMap::const_iterator i;
        for (i = m.constBegin(); i != m.constEnd(); ++i) {
            if (comma) res << ",\n"; else { res << '\n'; comma = true; }
            for (int c = indent; c > 0; c--) res << ' ';
            res << Json::quote(i.key()).toUtf8();
            res << ": ";
            if (!json_file_generate(res, i.value(), indent)) return false;
        }
        indent--;
        if (comma) {
            res << '\n';
            for (int c = indent; c > 0; c--) res << ' ';
        }
        res << '}';
        indent--;
    } break;
    case QVariant::List: {
        //for (int c = indent; c > 0; c--) res << ' ';
        res << "[";
        indent++; bool comma = false;
        QVariantList m(val.toList());
        foreach (const QVariant &v, m) {
            if (comma) res << ",\n"; else { res << '\n'; comma = true; }
            for (int c = indent; c > 0; c--) res << ' ';
            if (!json_file_generate(res, v, indent)) return false;
        }
        indent--;
        if (comma) {
            res << '\n';
            for (int c = indent; c > 0; c--) res << ' ';
        }
        res << ']';
        indent--;
    } break;
    case QVariant::StringList: {
        //for (int c = indent; c > 0; c--) res << ' ';
        res << "[";
        indent++; bool comma = false;
        QStringList m(val.toStringList());
        foreach (const QString &v, m) {
            if (comma) res << ",\n"; else { res << '\n'; comma = true; }
            for (int c = indent; c > 0; c--) res << ' ';
            res << Json::quote(v).toUtf8();
        }
        indent--;
        if (comma) {
            res << '\n';
            for (int c = indent; c > 0; c--) res << ' ';
        }
        res << ']';
        indent--;
    } break;
    default: return false;
    }
    return true;
}
开发者ID:Anderty,项目名称:qutim,代码行数:71,代码来源:jsonfile.cpp


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