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
2 answers

Qt Json serialization

I have a QVariant which can contain a double, a QString, a Foo object, or anything. I would like to serialize my QVariant without knowing what it contains. I am trying to do the serialization like this: QJsonObject jsonObject; jsonObject["myObject"]…
artoon
  • 729
  • 2
  • 14
  • 41
0
votes
1 answer

QVariantList append

I tri to append a QVariant to another QVariant (which must be a QVariantList). QList listInt; listInt.append(1); QVariant v; v.setValue(listInt); if(v.canConvert(QVariant::List)) { QVariant v1; v1.setValue(5); …
artoon
  • 729
  • 2
  • 14
  • 41
0
votes
1 answer

Parse JSON with Array in QT

I want to parse a JSON in QT. The JSON looks like this: { "result": "ok", "phrase": "katze", "tuc": [ { "meaningId": -6468009888908805000, "meanings": [ { "text": "common name for animals", …
Matthias
  • 461
  • 7
  • 24
0
votes
0 answers

Nested QVariantMap

I'm using nested QVariantMap and have a problem with defining a method that takes a path (string list) and returns the pointer to low-level QVariantMaps: QVariantMap * getQVariantMap( QStringList spec) const { QVariantMap * deep_p =…
Valentin T.
  • 519
  • 3
  • 12
0
votes
1 answer

QVariant::QVariant(Qt::BrushStyle) is private

The following piece of code produces error while compiling with Qt 5 styleComboBox = new QComboBox; typedef QPair BrushPair; foreach (const BrushPair &pair, QList() << qMakePair(tr("No Brush"),…
0
votes
1 answer

qvariant_cast causing segfault

Within qt's item/view framework, I'm trying to save a QColorDialog as user data and then retrieve that dialog as the editor, as well as during paint, in a tableview. In my class constructor I do QStandardItem *item = new…
ryan0270
  • 1,135
  • 11
  • 33
0
votes
1 answer

QVariant is not able to distinguish between QDateTime and QString

I have a QDateTime object which I store in a QVariant and then I check the QVariant with type() but it behaves strangely when I check the type. void MainWindow::Test() { QDateTime myDate; // QDateTime; …
anbu selvan
  • 725
  • 3
  • 13
  • 41
0
votes
1 answer

QVariant conversion to QPainterPath

I have a problem right now with my mini-game I am making. The problem is as follows: I have created an level editor for my game and thus I had to create my own delegate and model, the problem occurs when I try to edit through a shapeeditor ( which…
0
votes
1 answer

Read array of custom metatype from QSettings

I have a problem with reading custom metatype data from QSetting. I have a class: class MusicOwner { public: MusicOwner() : songs_count(0), id(0) {} explicit MusicOwner(const Song &owner_radio); Song toOwnerRadio()…
shed
  • 121
  • 1
  • 8
0
votes
1 answer

C++ error: no matching function call from pointer to pointer reference using Qt and QVariant

I have a QObject subclass defined as such (inside a "Danbooru" namespace): #ifndef DANBOORUPOST_H #define DANBOORUPOST_H // Qt #include #include #include #include…
Einar
  • 4,727
  • 7
  • 49
  • 64
0
votes
1 answer

QVariant.value() Causing Problems

So I have a custom class Foo which has been registered as a metatype using the Q_DECLARE_METATYPE(Foo) macro at the end of the class definition. I can set items within a list, check to see if canConvert, but when I try to actually make an item of…
ElCraneo
  • 495
  • 1
  • 6
  • 11
0
votes
1 answer

Qt QDbus Sending Custom Types with QVariant

I'm trying to send a custom class ( "Span" ) inside a QVariant across the Dbus session bus in Qt between 2 simple applications. Span is a simple class that contains 2 double type properties. I have successfully sent and recovered a QVariant…
PhilBot
  • 748
  • 18
  • 85
  • 173
0
votes
1 answer

Map QVariant type to SQLite type

I need to convert type of QVariant variable to QString of SQLite data type. It seems, that QSqlDriver should do that, but I can't find any method for such conversion.
Funt
  • 399
  • 8
  • 23
-1
votes
1 answer

QVariant::fromValue(QMap) returns an empty map

I have a function, which parses the file and fills a QMap with entries and returns a QVariant with value of that map: QVariant FileParser::parseFile(QString filePath) { QMap toReturn; ... (parse the file and fill…
George
  • 578
  • 4
  • 21
-1
votes
1 answer

Cannot set QVariantMap as QML property

I want to export a QVariantMap property to QML, so I'm doing Q_PROPERTY(QVariantMap myData READ myData) and in myData() function I just do QVariantMap map; map.insert("ExampleKey", "key"); return map; and in QML either myData.ExampleKey…
user2563892
  • 553
  • 1
  • 7
  • 16
1 2 3
12
13