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

convert function return from ‘std::vector’ to ‘QVariant’

I am working on a QT based application.One of of my class is a child class of QAbstractTableModel. The data function has a return type of QVariant(Union).But i want to return a custom type std::vector Came to know about…
user671253
1
vote
2 answers

Is there an easy way of using the QVariant class with hexadecimal strings?

This code sample works as I would expect: v = QVariant("123456"); qDebug() << v; // QVariant(QString, "123456") v.convert(QVariant::Int); qDebug() << v; // QVariant(int, 123456) v.convert(QVariant::String); qDebug() << v; // QVariant(QString,…
Samuel Harmer
  • 4,264
  • 5
  • 33
  • 67
1
vote
1 answer

Convert a QStandardItemModel to a QVariant

I'm trying to send a QStandardItemModel-derived object to PythonQt, but I'm a little confused on how it needs to be sent. When I was using boost::python I had several controls like boost::noncopyable to ensure I wasn't recreating this object, but…
voodoogiant
  • 2,118
  • 6
  • 29
  • 49
1
vote
1 answer

Generic way to find out if a QVariant contains a valid number

Inconveniently, QVariant{"Test"}.canconvert() returns true. As far as I know, only QVariant::toInt(bool *ok) can tell, if the value actually can be converted to an int. But I cannot use this function in a template class when I don't know the…
Thomas Klier
  • 449
  • 4
  • 16
1
vote
1 answer

Errors in qvariant.h during compilation

I am getting a variety of compilation errors relating to qvariant when compiling my program. I have not modified the Qt libs/source, so why am I getting these errors? (What do they mean) /Qt/5.9.9/gcc_64/mkspecs/linux-g++ -o tl_ansi_codes.o…
TSG
  • 4,242
  • 9
  • 61
  • 121
1
vote
1 answer

Qt QMap.insert() failing

I have a levelObjects object that's a QList of QVariants of QMaps: QList< QVariant > levelObjects; Later on, when I try to change the value of something in one of the QMaps, it doesn't seem to do anything: qDebug() << "Before - " <<…
numegil
  • 1,916
  • 7
  • 26
  • 38
1
vote
1 answer

Update a MapCircle on QML using a signal from C++

I'm trying to update a MapCircle in QML from a signal in C++ and I'm veen having several issues with it all day. In my class I have a Q_PROPERTY which is read only and holds the GPS positions of 4 UAVs in a QVariantList class GCS: public QObject { …
MaskedAfrican
  • 196
  • 2
  • 12
1
vote
1 answer

Qt/C++ Serialize generic object into QSettings

I have several occurences in my application where I want to save a compound object into QSettings: template class AwsProperty { public: AwsProperty(T value, quint64 timestamp){ m_data = value; m_timestamp =…
Curunir
  • 1,186
  • 2
  • 13
  • 30
1
vote
1 answer

Store QPointer into a QVariant

Can I store a QPointer, for example a QPointer inside a QVariant and later extract it from it? I tried with: QObject *ob = new QObject(); QPointer qp(ob); QVariant qv(qp); But I got an error -…
sashoalm
  • 75,001
  • 122
  • 434
  • 781
1
vote
2 answers

QVariant wrapped pointers turn to null in QML

It seems like something is going wrong when pointer values transcend between C++ and QML world. I am using the plain old fromValue() and value() to convert to and from void *, and it does work as expected as long as the variant stays on the C++…
dtech
  • 47,916
  • 17
  • 112
  • 190
1
vote
1 answer

QVariant conversion doesn't recognize std::string called by my template

I have a function in a class header ("frame.h") that's supposed to convert a QString to a generic type, initializing it to a default value if the QString is empty, shown below. template static void setStat(T &val, QString &temp) { …
J. Doeling
  • 31
  • 6
1
vote
2 answers

How to display a 2 dimension qvariantlist in QML

I have a 2-dimension qvariantlist which I would like to display in QML. I have been trying with a Listview but it only display the dimensions that you indicate. Ex array[0] array1 ... The following code displays only the first dimension...: …
arodrprope
  • 51
  • 9
1
vote
2 answers

QVariant call a function of a stored object, defined in the main part of a project

The common part (crating a lib) of my project currently holds a interface Class of the type: class CanBeAddedToGroup{ public: void addToGroup(Group& )=0; } Now i also wantred to use the programm on a Class containing data in a QVariant, so i…
edisn
  • 58
  • 11
1
vote
0 answers

toInt() function using API version 2

I have a function usingQSettings to load my setting. However, if I set the API to version 2, using import sip, sip.setapi('QVariant', 2), for example, I get an error: 'unicode' has no attibute 'toInt(). When I set it to version 1, it works fine. How…
james.rio
  • 23
  • 1
  • 5
1
vote
0 answers

QVariant from QList>

I want to save a QList> as QVariant but I alway get the error QVariant::save: unable to save type 'QList >' (type id: 1042). I've implemente the streaming operator for MyClass and it works fine. QDataStream&…
RobRobRob
  • 67
  • 2
  • 10