本文整理汇总了C++中QVariant::data方法的典型用法代码示例。如果您正苦于以下问题:C++ QVariant::data方法的具体用法?C++ QVariant::data怎么用?C++ QVariant::data使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QVariant
的用法示例。
在下文中一共展示了QVariant::data方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setEditValue
void VectorPropertyWidgetItem::setEditValue( const QVariant& value )
{
int userType = value.userType();
if( userType == d->vector2d )
{
const Vector2f* vector = static_cast<const Vector2f*>( value.data() );
d->x->setValue( vector->x() );
d->y->setValue( vector->y() );
d->z->setVisible( false );
d->w->setVisible( false );
d->vectorDim = 2;
}
else if( userType == d->vector3d )
{
const Vector3f* vector = static_cast<const Vector3f*>( value.data() );
d->x->setValue( vector->x() );
d->y->setValue( vector->y() );
d->z->setValue( vector->z() );
d->w->setVisible( false );
d->vectorDim = 3;
}
else if( userType == d->vector4d )
{
const Vector4f* vector = static_cast<const Vector4f*>( value.data() );
d->x->setValue( vector->x() );
d->y->setValue( vector->y() );
d->z->setValue( vector->z() );
d->w->setValue( vector->w() );
d->vectorDim = 4;
}
}
示例2: if
ConfigAtom::ConfigAtom(QVariant &var, bool isMap) : deleteOnDestroy(false), typeMap(isMap), readOnly(false)
{
if (isMap && var.type() != QVariant::Map)
var = QVariantMap();
else if (!isMap && var.type() != QVariant::List)
var = QVariantList();
if (isMap)
map = reinterpret_cast<QVariantMap*>(var.data());
else
list = reinterpret_cast<QVariantList*>(var.data());
}
示例3: QByteArray
bool Nuria::Serializer::fieldToVariant (QVariant &value, bool &ignore) {
QByteArray typeName = QByteArray (value.typeName (), -1);
MetaObject *meta = this->d->finder (typeName);
if (meta) {
void *dataPtr = value.data ();
if (typeName.endsWith ('*')) {
dataPtr = *reinterpret_cast< void ** > (dataPtr);
}
if (this->d->curDepth == 1) {
ignore = true;
} else {
value = serializeImpl (dataPtr, meta);
}
return true;
}
// Variant::convert() triggers QVariant conversion internally
QVariant conv = Nuria::Variant::convert (value, QMetaType::QString);
if (conv.isValid ()) {
value = conv;
return true;
}
return false;
}
示例4: addUsersToCluster
void TabbedMainWindow::addUsersToCluster(QString hostname, QString usernamepassword, QListWidget *list1, QListWidget *list2) {
ProgressDialog progbar("CMClusters - Connecting...", "Please wait while a connection to the selected clusters are established!");
progbar.show();
for (int i = list1->count(); i --> 0;) {
if (list1->item(i)->isSelected()) {
QString userid = getSubstringBetween(list1->item(i)->text(), QString("("), QString(")"));
qDebug() << userid;
QListWidgetItem* userToRemove = list1->item(i);
QListWidgetItem* userToAdd = new QListWidgetItem(list1->item(i)->text());
QByteArray jsonString = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns=\"http://www.cisco.com/AXL/API/8.5\">";
jsonString += "<soapenv:Body><ns:executeSQLUpdate><sql>UPDATE enduser SET enduser.islocaluser = 't' WHERE enduser.userid = '" + userid.toLocal8Bit() + "'</sql></ns:executeSQLUpdate></SOAP-ENV:Envelope>";
QByteArray postDataSize = QByteArray::number(jsonString.size());
QUrl req("https://" + hostname.toLocal8Bit() + ":8443/axl/");
QNetworkRequest request(req);
request.setRawHeader("SOAPAction", "\"CUCM:DB ver=8.5 executeSQLUpdate\"");
request.setRawHeader("Authorization", "Basic " + usernamepassword.toLocal8Bit());
request.setRawHeader("Content-Type", "text/xml");
request.setRawHeader("Content-Length", postDataSize);
QNetworkAccessManager test;
QEventLoop loop;
connect(&test, SIGNAL(finished(QNetworkReply*)), &loop, SLOT(quit()));
QNetworkReply * reply = test.post(request, jsonString);
reply->ignoreSslErrors(); // Ignore only unsigned later on
connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onError(QNetworkReply::NetworkError)));
loop.exec();
QByteArray response = reply->readAll();
QVariant statusCode = reply->attribute( QNetworkRequest::HttpStatusCodeAttribute );
if ( !statusCode.isValid() ) {
qDebug() << "Failed...";
qDebug() << statusCode.data();
}
int status = statusCode.toInt();
if ( status != 200 ) {
QString reason = reply->attribute( QNetworkRequest::HttpReasonPhraseAttribute ).toString();
qDebug() << reason;
} else {
qDebug() << "Good reply";
qDebug() << response;
if (response.contains("<rowsUpdated>1</rowsUpdated>")) {
qDebug() << "Something went correct!";
delete userToRemove;
list2->addItem(userToAdd);
userToAdd->setBackground(QColor(0, 170, 255));//Correct the color scheme
} else {
qDebug() << "We fucked up!";
}
}
}
}
示例5: get
ReturnedValue QQmlValueTypeWrapper::get(const Managed *m, String *name, bool *hasProperty)
{
Q_ASSERT(m->as<QQmlValueTypeWrapper>());
const QQmlValueTypeWrapper *r = static_cast<const QQmlValueTypeWrapper *>(m);
QV4::ExecutionEngine *v4 = r->engine();
// Note: readReferenceValue() can change the reference->type.
if (const QQmlValueTypeReference *reference = r->as<QQmlValueTypeReference>()) {
if (!reference->readReferenceValue())
return Primitive::undefinedValue().asReturnedValue();
}
QQmlPropertyData *result = r->d()->propertyCache->property(name, 0, 0);
if (!result)
return Object::get(m, name, hasProperty);
if (hasProperty)
*hasProperty = true;
if (result->isFunction())
// calling a Q_INVOKABLE function of a value type
return QV4::QObjectMethod::create(v4->rootContext(), r, result->coreIndex);
#define VALUE_TYPE_LOAD(metatype, cpptype, constructor) \
if (result->propType == metatype) { \
cpptype v; \
void *args[] = { &v, 0 }; \
metaObject->d.static_metacall(reinterpret_cast<QObject*>(gadget), QMetaObject::ReadProperty, index, args); \
return QV4::Encode(constructor(v)); \
}
const QMetaObject *metaObject = r->d()->propertyCache->metaObject();
int index = result->coreIndex;
QQmlMetaObject::resolveGadgetMethodOrPropertyIndex(QMetaObject::ReadProperty, &metaObject, &index);
void *gadget = r->d()->gadgetPtr;
// These four types are the most common used by the value type wrappers
VALUE_TYPE_LOAD(QMetaType::QReal, qreal, qreal);
VALUE_TYPE_LOAD(QMetaType::Int, int, int);
VALUE_TYPE_LOAD(QMetaType::QString, QString, v4->newString);
VALUE_TYPE_LOAD(QMetaType::Bool, bool, bool);
QVariant v;
void *args[] = { Q_NULLPTR, Q_NULLPTR };
if (result->propType == QMetaType::QVariant) {
args[0] = &v;
} else {
v = QVariant(result->propType, static_cast<void *>(Q_NULLPTR));
args[0] = v.data();
}
metaObject->d.static_metacall(reinterpret_cast<QObject*>(gadget), QMetaObject::ReadProperty, index, args);
return v4->fromVariant(v);
#undef VALUE_TYPE_ACCESSOR
}
示例6: invokeMethod
QJsonValue QMetaObjectPublisher::invokeMethod(QObject *const object, const int methodIndex,
const QJsonArray &args)
{
const QMetaMethod &method = object->metaObject()->method(methodIndex);
if (method.name() == QByteArrayLiteral("deleteLater")) {
// invoke `deleteLater` on wrapped QObject indirectly
deleteWrappedObject(object);
return QJsonValue();
} else if (!method.isValid()) {
qWarning() << "Cannot invoke unknown method of index" << methodIndex << "on object" << object << '.';
return QJsonValue();
} else if (method.access() != QMetaMethod::Public) {
qWarning() << "Cannot invoke non-public method" << method.name() << "on object" << object << '.';
return QJsonValue();
} else if (method.methodType() != QMetaMethod::Method && method.methodType() != QMetaMethod::Slot) {
qWarning() << "Cannot invoke non-public method" << method.name() << "on object" << object << '.';
return QJsonValue();
} else if (args.size() > 10) {
qWarning() << "Cannot invoke method" << method.name() << "on object" << object << "with more than 10 arguments, as that is not supported by QMetaMethod::invoke.";
return QJsonValue();
} else if (args.size() > method.parameterCount()) {
qWarning() << "Ignoring additional arguments while invoking method" << method.name() << "on object" << object << ':'
<< args.size() << "arguments given, but method only takes" << method.parameterCount() << '.';
}
// construct converter objects of QVariant to QGenericArgument
VariantArgument arguments[10];
for (int i = 0; i < qMin(args.size(), method.parameterCount()); ++i) {
QVariant arg = args.at(i).toVariant();
if (method.parameterType(i) != QMetaType::QVariant && !arg.convert(method.parameterType(i))) {
qWarning() << "Could not convert argument" << args.at(i) << "to target type" << method.parameterTypes().at(i) << '.';
}
arguments[i].value = arg;
}
// construct QGenericReturnArgument
QVariant returnValue;
if (method.returnType() != qMetaTypeId<QVariant>() && method.returnType() != qMetaTypeId<void>()) {
// Only init variant with return type if its not a variant itself, which would
// lead to nested variants which is not what we want.
// Also, skip void-return types for obvious reasons (and to prevent a runtime warning inside Qt).
returnValue = QVariant(method.returnType(), 0);
}
QGenericReturnArgument returnArgument(method.typeName(), returnValue.data());
// now we can call the method
method.invoke(object, returnArgument,
arguments[0], arguments[1], arguments[2], arguments[3], arguments[4],
arguments[5], arguments[6], arguments[7], arguments[8], arguments[9]);
return wrapResult(returnValue);
}
示例7: nativeSessionId
int toQPSqlConnectionSub::nativeSessionId()
{
QVariant v = Connection.driver()->handle();
if (v.isValid() && v.typeName() == QString("PGconn*"))
{
#ifdef HAVE_POSTGRESQL_LIBPQ_FE_H
PGconn *handle = *static_cast<PGconn **>(v.data());
if (handle)
return PQbackendPID(handle);
#endif
}
return 0;
}
示例8: invokeMethodWithVariants
/* taken from http://delta.affinix.com/2006/08/14/invokemethodwithvariants/
thanks to Justin Karneges once again :) */
bool MaiaXmlRpcServerConnection::invokeMethodWithVariants(QObject *obj,
const QByteArray &method, const QVariantList &args,
QVariant *ret, Qt::ConnectionType type) {
// QMetaObject::invokeMethod() has a 10 argument maximum
if(args.count() > 10)
return false;
QList<QByteArray> argTypes;
for(int n = 0; n < args.count(); ++n)
argTypes += args[n].typeName();
// get return type
int metatype = 0;
QByteArray retTypeName = getReturnType(obj->metaObject(), method, argTypes);
if(!retTypeName.isEmpty() && retTypeName != "QVariant") {
metatype = QMetaType::type(retTypeName.data());
if(metatype == 0) // lookup failed
return false;
}
QGenericArgument arg[10];
for(int n = 0; n < args.count(); ++n)
arg[n] = QGenericArgument(args[n].typeName(), args[n].constData());
QGenericReturnArgument retarg;
QVariant retval;
if(metatype != 0) {
retval = QVariant(metatype, (const void *)0);
retarg = QGenericReturnArgument(retval.typeName(), retval.data());
} else { /* QVariant */
retarg = QGenericReturnArgument("QVariant", &retval);
}
if(retTypeName.isEmpty()) { /* void */
if(!QMetaObject::invokeMethod(obj, method.data(), type,
arg[0], arg[1], arg[2], arg[3], arg[4],
arg[5], arg[6], arg[7], arg[8], arg[9]))
return false;
} else {
if(!QMetaObject::invokeMethod(obj, method.data(), type, retarg,
arg[0], arg[1], arg[2], arg[3], arg[4],
arg[5], arg[6], arg[7], arg[8], arg[9]))
return false;
}
if(retval.isValid() && ret)
*ret = retval;
return true;
}
示例9: invoke
/*!
Invokes the slot represented by this object with the argument
list \a args. The slot's return value is returned from
this method. If the slot's return type is "void", then a
QVariant instance of type QVariant::Invalid will be returned.
If it is possible that the slot may throw an exception,
it is the responsibility of the caller to catch and
handle the exception.
\since 1.1
*/
QVariant QSlotInvoker::invoke( const QList<QVariant>& args )
{
int arg;
QVariant returnValue;
// Create a default instance of the return type for the result buffer.
if ( d->returnType != (int)QVariant::Invalid ) {
returnValue = QVariant( d->returnType, (const void *)0 );
}
// Bail out if the receiver object has already disappeared.
if ( d->destroyed )
return returnValue;
// Check that the number of arguments is compatible with the slot.
int numArgs = args.size();
if ( numArgs < d->numArgs ) {
qWarning( "QSlotInvoker::invoke: insufficient arguments for slot" );
return returnValue;
} else if ( numArgs > d->numArgs ) {
// Drop extraneous arguments.
numArgs = d->numArgs;
}
// Construct the raw argument list.
QVarLengthArray<void *, 32> a( numArgs + 1 );
if ( d->returnType == (int)QVariant::Invalid )
a[0] = 0;
else
a[0] = returnValue.data();
for ( arg = 0; arg < numArgs; ++arg ) {
if ( d->types[arg] == QSignalIntercepter::QVariantId ) {
a[arg + 1] = (void *)&( args[arg] );
} else if ( args[arg].userType() != d->types[arg] ) {
qWarning( "QSlotInvoker::invoke: argument %d has incorrect type",
arg );
return QVariant();
} else {
a[arg + 1] = (void *)( args[arg].data() );
}
}
// Invoke the specified slot.
d->receiver->qt_metacall( QMetaObject::InvokeMetaMethod,
d->memberIndex, a.data() );
return returnValue;
}
示例10: writeProperty
void QQmlVMEMetaObject::writeProperty(int id, const QVariant &value)
{
if (id >= firstVarPropertyIndex) {
if (!ensureVarPropertiesAllocated())
return;
QV4::Scope scope(varProperties.engine());
// Importantly, if the current value is a scarce resource, we need to ensure that it
// gets automatically released by the engine if no other references to it exist.
QV4::ScopedObject vp(scope, varProperties.value());
QV4::Scoped<QV4::VariantObject> oldv(scope, vp->getIndexed(id - firstVarPropertyIndex));
if (!!oldv)
oldv->removeVmePropertyReference();
// And, if the new value is a scarce resource, we need to ensure that it does not get
// automatically released by the engine until no other references to it exist.
QV4::ScopedValue newv(scope, QQmlEnginePrivate::get(ctxt->engine)->v8engine()->fromVariant(value));
QV4::Scoped<QV4::VariantObject> v(scope, newv);
if (!!v)
v->addVmePropertyReference();
// Write the value and emit change signal as appropriate.
QVariant currentValue = readPropertyAsVariant(id);
vp->putIndexed(id - firstVarPropertyIndex, newv);
if ((currentValue.userType() != value.userType() || currentValue != value))
activate(object, methodOffset() + id, 0);
} else {
bool needActivate = false;
if (value.userType() == QMetaType::QObjectStar) {
QObject *o = *(QObject **)value.data();
needActivate = (data[id].dataType() != QMetaType::QObjectStar || data[id].asQObject() != o);
data[id].setValue(o, this, id);
} else {
needActivate = (data[id].dataType() != qMetaTypeId<QVariant>() ||
data[id].asQVariant().userType() != value.userType() ||
data[id].asQVariant() != value);
data[id].setValue(value);
}
if (needActivate)
activate(object, methodOffset() + id, 0);
}
}
示例11: testQVariant2
void testQVariant2()
{
QVariant value;
QVariant::Type t = QVariant::String;
value = QVariant(t, (void*)0);
*(QString*)value.data() = QString("XXX");
int i = 1;
Q_UNUSED(i);
#if 1
QVariant var;
var.setValue(1);
var.setValue(2);
var.setValue(3);
var.setValue(QString("Hello"));
var.setValue(QString("World"));
var.setValue(QString("Hello"));
var.setValue(QStringList() << "World");
var.setValue(QStringList() << "World" << "Hello");
var.setValue(QStringList() << "Hello" << "Hello");
var.setValue(QStringList() << "World" << "Hello" << "Hello");
#endif
#if 1
QVariant var3;
QHostAddress ha("127.0.0.1");
var.setValue(ha);
var3 = var;
var3 = var;
var3 = var;
var3 = var;
QHostAddress ha1 = var.value<QHostAddress>();
typedef QMap<uint, QStringList> MyType;
MyType my;
my[1] = (QStringList() << "Hello");
my[3] = (QStringList() << "World");
var.setValue(my);
// FIXME: Known to break
QString type = var.typeName();
var.setValue(my);
var.setValue(my);
var.setValue(my);
var.setValue(my);
#endif
}
示例12: TrainerModel
SqliteTrainerModel::SqliteTrainerModel(QObject *parent, QString fileName) :
TrainerModel(parent)
{
m_cardItemModel = new CardItemModel(this);
m_cardItemModel->setObjectName("card_items");
QSqlError err;
QSqlDatabase db = QSqlDatabase::database(fileName);
if(!db.isValid()) {
db = QSqlDatabase::addDatabase("QSQLITE", fileName);
db.setDatabaseName(fileName);
}
if (!db.open()) {
err = db.lastError();
db = QSqlDatabase();
QSqlDatabase::removeDatabase(fileName);
}
if(err.isValid()) {
qWarning() << err.text();
} else {
qDebug() << fileName << "opened";
m_db = db;
QVariant v = db.driver()->handle();
if (v.isValid() && qstrcmp(v.typeName(), "sqlite3*")==0) {
// v.data() returns a pointer to the handle
sqlite3 *handle = *static_cast<sqlite3 **>(v.data());
if (handle != 0) { // check that it is not NULL
sqlite3_trace(handle,trace,NULL);
}
}
initCardItemModel();
initModels();
}
}
示例13: qDBusReplyFill
/*!
\internal
Fills in the QDBusReply data \a error and \a data from the reply message \a reply.
*/
void qDBusReplyFill(const QDBusMessage &reply, QDBusError &error, QVariant &data)
{
error = reply;
if (error.isValid()) {
data = QVariant(); // clear it
return;
}
if (reply.arguments().count() >= 1 && reply.arguments().at(0).userType() == data.userType()) {
data = reply.arguments().at(0);
return;
}
const char *expectedSignature = 0;
QByteArray receivedSignature;
if (reply.arguments().count() >= 1 &&
reply.arguments().at(0).userType() == QDBusMetaTypeId::argument) {
// compare signatures instead
QDBusArgument arg = qvariant_cast<QDBusArgument>(reply.arguments().at(0));
expectedSignature = QDBusMetaType::typeToSignature(data.userType());
receivedSignature = arg.currentSignature().toLatin1();
if (receivedSignature == expectedSignature) {
// matched. Demarshall it
QDBusMetaType::demarshall(arg, data.userType(), data.data());
return;
}
}
// error
QString errorMsg = QLatin1String("Unexpected reply signature: got \"%1\", "
"expected \"%2\" (%3)");
if (receivedSignature.isEmpty())
receivedSignature = "no signature";
error = QDBusError(QDBusError::InvalidSignature,
errorMsg.arg(QLatin1String(receivedSignature),
QLatin1String(expectedSignature),
QLatin1String(data.typeName())));
data = QVariant(); // clear it
}
示例14: nativeCancel
void toQPSqlConnectionSub::nativeCancel()
{
QVariant v = Connection.driver()->handle();
if (v.isValid() && v.typeName() == QString("PGconn*"))
{
#ifdef LIBPQ_DECL_CANCEL
PGconn *handle = *static_cast<PGconn **>(v.data());
if (!handle)
return;
PGcancel *cancel = PQgetCancel(handle);
if (!cancel)
return;
char *errbuf = new char[1024];
PQcancel(cancel, errbuf, 1024);
PQfreeCancel(cancel);
delete[] errbuf;
#endif
}
}
示例15: AddList
// Author & Date: Ehsan Azar 19 April 2012
// Purpose: Add list iteratively
// Inputs:
// list - list to add to current node
// nodeName - last node name
// Outputs:
// Returns true if this is an array added
bool XmlFile::AddList(QVariantList & list, QString nodeName)
{
if (list.isEmpty())
return false;
QMap<QString, int> mapItemCount;
int count = 0, subcount = 1;
// itemize the list
for (int j = 0; j < list.size(); ++j)
{
QVariant subval = list[j];
if (!subval.isValid())
continue;
count++; // count all valid items
QString strSubKey;
QMap<QString, QVariant> attribs;
if (subval.type() == QVariant::UserType)
{
const XmlItem * item = static_cast<const XmlItem *>(subval.data());
strSubKey = item->XmlName();
attribs = item->XmlAttribs();
}
if (strSubKey.isEmpty())
strSubKey = nodeName + "_item";
subcount = mapItemCount[strSubKey];
mapItemCount[strSubKey] = subcount + 1;
if (subcount)
strSubKey = strSubKey + QString("<%1>").arg(subcount);
// Recursively add this item
beginGroup(strSubKey, attribs, subval);
endGroup();
} // end for (int j
// If all items had same tag name, it is an array
if (count > 1 && count == subcount + 1)
return true;
return false;
}