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

QVariant use the type to static cast another variable

I create a structure with some variables to be able to use it and compare its value with range, or use on a data model with my QML GUI: struct DataStruct { DataStruct(QString name = "", QVariant value = QVariant(), QVariant minValue =…
Mathieu Gauquelin
  • 601
  • 11
  • 35
0
votes
1 answer

Inconsistent conversion of QVariant to double

I'm having trouble understanding the behaviour of QVariant::canConvert and QVariant::toDouble. I'd expect that both of these would return false if the underlying variant data is, say, a QString, but I'm getting different results as shown: #include…
linuxfever
  • 3,763
  • 2
  • 19
  • 43
0
votes
1 answer

(Qt) Change value by key in QVariantMap nested in QVariantList (which is also nested in QVariantMap)

There is the following hierarchy: QVariantMap <- QVariantList <- QVariantMap The problem is QVariant::toList() and QVariant::toMap() return copies, which means I can't change value in a nested QVariantMap or QVariantList. Is there any way to solse…
0
votes
1 answer

QVariantMap dosen't work in QML with Clang Compiler - Segmentation fault

I have a problem with passing Q_PROPERTY as QVariantMap to QML - Segmentation fault. I created simple app to show the problem. When I'm using compiler MinGW 11.2 everything is fine, but the problem is under Clang 15.0.4. I have installed Clang by…
ducho
  • 3
  • 2
0
votes
1 answer

How to Serialize Custom Objects in Qt6

I have a custom class Dummy which I want to send as an object using Dynamic Replica in Qt6. I'm able to send the class but it's being transferred as QVariant which I'm not able to extract(or cast) from QVariabnt object. Below is my…
0
votes
0 answers

Convert QVariant to QString causes error randomly

I have a qtableview, some of its columns' data are like: [20,1647.8,2101.2,1911.6, ... ,-1.6915] It's basically an array of float values separated by comma and wrapped up by square brackets. But the first one is an integer telling how many values in…
0
votes
1 answer

Is there possible pass Javascript Object from qml as QVariant to c++ layer as a parameter of slot?

I try to pass Object from qml to c++ as a parameter of slot, is it possible to get in c++? In slot in c++ I have empty variable QVariant(QJSValue, ). I need to pass Object as a map to c++ (QMap). Is it possible to pass an object…
0
votes
2 answers

How can I *directly* append to a QVariantList, stored in a QVariantMap?

I have a collection of QVariantMaps which contains QVariantLists in SOME of their entries. I need to append to the lists. These lists can grow rather large, and I have to do this for many of them, many times per second, basically the whole time the…
BuvinJ
  • 10,221
  • 5
  • 83
  • 96
0
votes
0 answers

how to properly declare a qvariantlist and initialize it so i can put my custom object/class into it by appending

i cannot figure out how to use a qvariantlist from all the examples i find i need to stuff filenames-sizes-checksum for multiple files in a csv file and be able to search through them later here is the part where i'm stuck QVariantList…
adam
  • 67
  • 8
0
votes
0 answers

Qt 4.8, canConvert with template

i would like to create a converter based on QVariant. I have make this methode: find() template T find(const QVariant variant, T type) { if (variant.canConvert()){ return variant; } return T(); } It is called like…
0
votes
1 answer

c++ qt can i fill a QVariant with multiple struct objects

I have the following struct: struct FileInfo { QString fileName; QString fileSize; QString md5Sum; }; is it possible to put approximately 30 such objects into a QVariant and then be able to iterate through the QVariant to retrieve one of the…
adam
  • 67
  • 8
0
votes
2 answers

QMultiMap with QVariant as key

I have a multimap with QVariant as key, but it's not working with QByteArray. The funcion map.values("\xc2\x39\xc7\xe1") is returning all the values of the map. This is a small example: #include #include #include…
Fausto01
  • 171
  • 14
0
votes
2 answers

QVariantMap crash in destructor

I am building a JSON-object with Qt and convert it to a QString using QJson. This (normally) works fine and it does in this case but in the destructor of my Qt data structure, it crashes with an Access Violation. The Object is built fine, it is sent…
Tobias
  • 737
  • 1
  • 9
  • 20
0
votes
2 answers

Unit Testing with QVariant

I want to make a unit-test for a function returning a qvariant to make sure if the qvariant is holding the right vlaue or not Please give me some idea to how should i proceed?
Puneet
  • 291
  • 1
  • 5
  • 15
0
votes
1 answer

Why can't I change the Qvariant value inside a QMap?

I'm trying to pass an object called QMap* collect_row and then I'm going to fill the second element with a QVariant value. The current value in the second element is 0. I'm using this code to connect to a database and then copy…
euraad
  • 2,467
  • 5
  • 30
  • 51