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

Is there a way to use QVariant with QVector?

Is there a way to use QVariant with QVector? I would need to implement a function to compare two vectors, for example: #include #include #include bool compareVectors(QVector vec1, QVector vec2) { …
KelvinS
  • 2,870
  • 8
  • 34
  • 67
0
votes
0 answers

Qt retrieve QFlags form QVariant

Here is a code exemple: #include enum Pouet { F1 = 1, F2 = 2, F3 = 4, }; Q_DECLARE_FLAGS(Pouets, Pouet) Q_DECLARE_METATYPE(Pouets) Q_DECLARE_OPERATORS_FOR_FLAGS(Pouets) int main(int argc, char *argv[]) { Pouets p =…
NiHoT
  • 342
  • 5
  • 17
0
votes
0 answers

Save QList> as QVariant

I have a problem saving a QList of QSharedPointer< MyClass > as QVariant in a derived QGraphicsItem class. MyClass is an abstract base class used as an interface. I made this to be able to up cast all 'MyClass subclasses' to the base MyClass and put…
RobRobRob
  • 67
  • 2
  • 10
0
votes
1 answer

Setting QML context fail

I am trying to connect a C++ class to QML but I am facing a problem, the following errors appear when compile. I am adding an image to show the errors: I am using a simple class just to test if my code works , here is the code testing.h: #ifndef…
Meddah Abdallah
  • 654
  • 1
  • 7
  • 25
0
votes
1 answer

Undeclared identifier 'QVariant' convert legacy Qt 4 to 5

I need to convert Qt legacy code from 4.7 to 5.8, I have a compilation error in Qt Creator 4.2.1 Clang 7.0(Apple) 64bit Looking in .cpp file bool queries::insert(const QString &tableName_, const QMap &values_) const Error in…
bullflag
  • 99
  • 1
  • 8
0
votes
1 answer

QSettings setvalue method writes QVariant datatype to windows registry

I try to update FTDI settings from windows registry. I can read and modify the ConfigData values from registry and change some values with converting it to QByteArray. QSettings…
0
votes
1 answer

Qvariant usage instead of union

So far in my project where I had to store different data types in one place and in the end send them through a medium bytewise, I always used a custom union: union union64_t { quint16 u16[4]; qint16 i16[4]; quint32 u32[2]; qint32 …
Łukasz Przeniosło
  • 2,725
  • 5
  • 38
  • 74
0
votes
3 answers

Convert QVariant to float

I have some trouble to get my float value out of a QVariant. I call a function, which returns a QVariant, but when I convert it to a float value, like this: float resf = result.toFloat(); The result is always 0.0000000. That's not the result I…
snucker
  • 31
  • 1
  • 7
0
votes
1 answer

QVariant returns invalid meanwhile the value is valid

I have a small function like this bool QcgDatabase::onceindb(const QString& userId) { mDb->prepareSqlQuery("SELECT count(*) FROM mytable WHERE userid=:userId;", "database"); mDb->prepareBindValue(":userId", userId); mDb->sqlExec(); …
trangan
  • 341
  • 8
  • 22
0
votes
1 answer

QComboBox::findData fails when QVariant stores a std::vector

Consider this code: std::vector< std::vector > v; v.push_back( std::vector( 1, 4 ) ); v.push_back( std::vector( 1, 3 ) ); QComboBox box; box.addItem( "", QVariant::fromValue>( v[0] ) ); box.addItem( "",…
jpo38
  • 20,821
  • 10
  • 70
  • 151
0
votes
1 answer

Storing dynamically QML objects

i want to store in a variant or a list, a set of dynamically QML created objects. when i do it once, it works nice: property var obj var component = Qt.createComponent("MyObject.qml") obj = componente.createObject(contenedor) i am…
walolinux
  • 531
  • 1
  • 6
  • 20
0
votes
1 answer

Replacing QVariant::Handler::canConvert

Is it possible to inject our own code into QVariant::canConvert? I'm adding support for converting between our own all-purpose value container and the Qt version (QVariant), based mostly on a suggestion here How to support comparisons for QVariant…
FrozenKiwi
  • 1,362
  • 13
  • 26
0
votes
1 answer

PySide TableView and Variant data - Display Role Not Displaying

I have this code, which when i run it in PyQt it works totally fine, but when i run it in pyside things get wierd. I get all the columns and rows im supposed to, and if i go to them via scripting and get the data, each cell says what it should.…
Alex
  • 95
  • 1
  • 7
0
votes
1 answer

QVariant custom classes polymorphism

I have such a classes hierarchy: class Base { ... virtual QWidget* getEditor(); ... } class Derived { ... QWidget* getEditor() Q_DECL_OVERRIDE; ... } Both classes are registered via Q_DECLARE_METATYPE() I'm getting instance of Base class from…
Eckler
  • 61
  • 1
  • 8
0
votes
1 answer

Update item in qvariantlist

I am a bit lost with QVariantMAP/List and reference. I load a json with QJson and convert it to QVariantMAP. currentJSON["tests"] is a QVariantList I wish to browse currentJSON["tests"] and update the value of item["label"]. The first loop try to…