Questions tagged [qvariant]

QVariant is a data type in Qt library, that acts as a "container" for most of the common Qt data types.

QVariant can contain most of the basic Qt data types, and perform easy conversions between them. QVariant can also contain tree-like structures, which is shown in this small example:

//Creating a list of QVariants.
QVariantList myList;
//Creating a single QVariant variable
QVariant var;
//Populating the list with different types
myList << "Hello, world!";
myList << 15;
myList << 0x0A;
//After the following assignment, the variable will hold the list.
var = myList;

The official Qt documentation can be found here for Qt 4.8 and here for Qt 5.

181 questions
0
votes
1 answer

How can I get the raw binary content from an arbitrary typed QVariant into a QBytearray?

Problem I have an interface which gives me a QVariant of an arbitrary type. I need to convert the data content in this variant to a raw binary QByteArray: QVariant result = myQVariantReturningMethod(type arg, type arg2); QByteArray rawResult =…
darkmattercoder
  • 325
  • 6
  • 26
0
votes
1 answer

How to avoid creating copy when calling QVariant::toMap()?

I am storing QVariantMap as QVariant inside another QVariant. I need to add fileds in this nested QVariantMap in an slot function. Here is what I have so far:- QVariantMap map = data["nestedMap"].toMap(); //first copy map[newfield] =…
너를 속였다
  • 899
  • 11
  • 26
0
votes
2 answers

How to call "QList QVariant::toList () const"

This is a pretty simple and probably dumb question, but I have forgotten how to use QList QVariant::toList () const QVariant s = this->page()->mainFrame()->evaluateJavaScript (QString ("Open(%1,%2)").arg (point.x()).arg (point.y())); List
Aquarius_Girl
  • 21,790
  • 65
  • 230
  • 411
0
votes
0 answers

Does QVariant call a destructor on the contained class?

If I put a class with a destructor in a QVariant, will the QVariant's destruction call the proper destructor of the non-POD class it contains? Here's an example, where I'm putting a class into a QVariant owned by a QWidget: QVariant variant =…
Jamin Grey
  • 10,151
  • 6
  • 39
  • 52
0
votes
1 answer

Store QList in QVariant

I have a class defined as this: cdataentry.h: #ifndef CDATAENTRY_H #define CDATAENTRY_H #include #include #include #include #include #include #include /** *…
Łukasz Przeniosło
  • 2,725
  • 5
  • 38
  • 74
0
votes
1 answer

Difference between QJsonValue and QVariant?

I'm working with Qt and JSON. Now, I have two options: QVariant and QJsonValue. I don't get the point in which they are different? I know QVariant has some more methods and QJsonValue has the is*** methods(where QVariant has type). But is there any…
ratloser
  • 116
  • 1
  • 7
0
votes
1 answer

Drag and drop in QTreeWidget with custom class (Error :Qvariant::save)

my problem is the following : I want to use a drag and drop in my QTreeWidget. My QtreeWidgetItem have the following flags Enabled | selectable |Drag | Drop. It works for an item but don't for the rest (Error Qvariant::Save invalid type to…
Samael
  • 61
  • 1
  • 9
0
votes
1 answer

Why I can't store QVariantMap in QSettings?

Why it was possible in Qt 5.2 and previously and stored data in following format: key=@Variant(\0\0\0\b\0\0\0) but have problem now in Qt 5.11?! Following code QVariantMap projectsMap; for (auto project : projects) projectsMap.insert(key,…
Aleksey Kontsevich
  • 4,671
  • 4
  • 46
  • 101
0
votes
1 answer

Save custom QMap template instantiation in QSettings in human-readable form

In my code, I use the QSettings mechanism to save and load my own class MyClass inside a QMap into config files. I know how to register my own types to QMetaObject so I can use them with QVariant. This allows to save them with…
perivesta
  • 3,417
  • 1
  • 10
  • 25
0
votes
1 answer

Get object handler user clicked in scene

QList list; In scene user can add no of objects and m storing objects in list. i want to get the object the user clicked or focused one so that i can change properties or delete object. how to get clicked object pointer from list ?
Sagar A W
  • 338
  • 1
  • 12
0
votes
1 answer

How to convert QVariant to QDomNode

I have a simple DOM model for working with XML (from this tutorial: http://doc.qt.io/qt-5/qtwidgets-itemviews-simpledommodel-example.html). Now in my code I want to get data by index like this: auto data = model_->data(index, Qt::DisplayRole); But…
Count Zero
  • 495
  • 6
  • 15
0
votes
1 answer

Its possible write an context property on QML from C++?

I need to create the context property "model(QAbstractItemModel)" from C++. But, i just know the QQmlProperty::write(...), and this method just accepts QVariant as value for the property. Any suggestion?
Jhonny Pinheiro
  • 308
  • 3
  • 19
0
votes
2 answers

Convert an instance of QObject to JSON

I have some code that I am using to convert arbitrary QObject subclasses to JSON. I able to convert them if they are pointers to a subclass, but am curious whether it is possible to convert instances (provided the subclass implements a copy…
Cobalt
  • 938
  • 9
  • 21
0
votes
2 answers

Using QTreeWidgetItems setData to store a QStackedWidget or QVariant

I am trying to make a QTreeWidget such that each row contains a series of comboboxes. Depending on how the user interacts with the comboboxes I would like certain comboboxes to becomes line edits and some to become buttons. It was suggested here…
0
votes
1 answer

Passing rvalue reference to QVariant does not work with QString

I am trying to return a rvalue reference from a function to a QVariant. It works for bool and int, but when I pass a string I get an 'invalid' QVariant. My function: QVariant &&AudioSettings::getValueFromTable(const QString &name) { QSqlQuery…
Szpaqn
  • 545
  • 5
  • 17