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
1
vote
1 answer

How to get data in form of QString from QVariant in Qt5?

I have a QVariant with userType QVariantList and the exact format looks like this when i qDebug the qvariant QVariant(QVariantList, (QVariant(QVariantMap, QMap(("name", QVariant(QString, "UK English Female")))) I want QString, "UK English Female"…
bulldog68
  • 197
  • 1
  • 10
1
vote
1 answer

PyQt5 - QVariant.value() returns object instead of python value (pyqt4 .toPyObject())

Based on the SO example here and the below output: from PyQt4.QtCore import QVariant data = {'key1': 123, 'key2': 456} v = QVariant((data,)) v.toPyObject()[0] >>> {'key2': 456, 'key1': 123}` I try to accomplish this for pyqt5 but with partial…
ZF007
  • 3,708
  • 8
  • 29
  • 48
1
vote
1 answer

conversion between std::string and QVariant (and vice versa) Qt5

I'm having a hard time of converting std::string to QVariant and QVariant back to std::string. In both cases I end up with empty value (default QVariant, just like it was initialized with no parameters) and empty std::string (""). These are relevant…
pzaj
  • 1,062
  • 1
  • 17
  • 37
1
vote
1 answer

QVariant conversion with value() can't be checked

I want to convert a QVariant that stores a string to a value with the template method value(). The same thing can be done with other methods like toInt(), toDouble() and so no. My problem now is that using for example toDouble(bool *ok = Q_NULLPTR)…
Elia
  • 1,417
  • 1
  • 18
  • 28
1
vote
1 answer

Qt Throwing Illegal Error at QVariant

I have some code that is meant to get a QList of QMaps from a set of data. Then it should go through all the QMaps in that list. For some reason upon attempting this I am getting some errors regarding the QVector used to store data. Here is my…
Nicholas Johnson
  • 1,012
  • 2
  • 12
  • 35
1
vote
0 answers

Null pointer returned to QML is true in conditional statements

Investigating a crash I found out that a non-QObject derived registered meta type always passes if (obj) checks even if it contains a nullptr. Outputting the return value says QVariant(Base*) rather than null. I suspect that QVariant::isNull() might…
dtech
  • 47,916
  • 17
  • 112
  • 190
1
vote
1 answer

How do I use QComboBox in relation with QVariant?

As I understood, QComboBox can hold a text (i.e. the name) and data (i.e. an object). My QComboBox should store QSizeF's, while showing nice names. Hence I would like to do something like this: void fillComboBox() { ui->combobox->addItem("big",…
dani
  • 3,677
  • 4
  • 26
  • 60
1
vote
0 answers

ASSERT failure in QVariant: "Trying to construct an unknown type", file kernel\qvariant.cpp, line 980

Qt 5.5.0 I'm switching one of my gui applications to console. I'm having a problem with QSettings object initiation in console mode. This is the code in gui, it works fine: class MainWindow : public QMainWindow { Q_OBJECT public: …
desto
  • 19
  • 2
1
vote
0 answers

Trouble of mutating QList which is actually QVariant without copying it

Unfortunately, our software uses certain data-holding object called ProcessContext which holds the data in string indexed map (QMap. This patter will not be changed right now but I need to stuff more complex data than string and…
Tomáš Zato
  • 50,171
  • 52
  • 268
  • 778
1
vote
1 answer

QFlags and QVariant

What I am trying to do is to simply store a QFlags in a QVariant. The Flags definition: class EnumObject : public QObject { Q_OBJECT public: enum DemoFlag { SomeFlag0 = 0x00, SomeFlag1 = 0x01, SomeFlag2 = 0x02 }; …
Felix
  • 6,885
  • 1
  • 29
  • 54
1
vote
2 answers

How to convert QComboBox value to int in QT

i'm making a simple calculator using Qt with QT Creator I want to convert a value from QCombobox (that conatain the operations :'+' , '-', '*','/') to int so i have used this : // operation is the name of my QComboBox :) QVariant i = ui -> operation…
The Beast
  • 1,629
  • 2
  • 29
  • 42
1
vote
1 answer

QML Qvariant from custom class

I have my custom C++ class: Media.h: #ifndef MEDIA_H #define MEDIA_H class Media { public: explicit Media(); virtual ~Media(); void setAllMedia(QString id, QString type, QString media, QString meta); signals: private…
walolinux
  • 531
  • 1
  • 6
  • 20
1
vote
2 answers

How to use QVariant::fromValue with QString?

I have the following code: QString* data = new QString("data to QML"); engine.rootContext()->setContextProperty(QStringLiteral("consoleText"), QVariant::fromValue(data)); and this one does not work, the error message in QTCreator is the…
Bence Kaulics
  • 7,066
  • 7
  • 33
  • 63
1
vote
0 answers

QSqlTableModel inserting new record, getting data is QVariant(invalid)

I have a simple QSqlTableModel: class UsersModel : public QSqlTableModel { Q_OBJECT public: UsersModel(); ~UsersModel(); bool newUser(const QString &name, const QString &surname, const QString…
Pavel K.
  • 11
  • 3
1
vote
1 answer

How to get Python List from QVariant

If Qt.UserRole the model's headerData() returns a Python list variable: if role==Qt.UserRole: return QVariant(['one','two','three']) Instead of a regular Python list a function that calls with: returnedValue = myModel(index.column(),…
alphanumeric
  • 17,967
  • 64
  • 244
  • 392