QVariant

QVariant is a class that can hold values of multiple types:

QVariant intValue = 1;int x = intValue.toInt();QVariant stringValue = "ok";QString y = stringValue.toString();

When you assign a value to a QVariant object, that value is stored inside along with the type information. You can use its type() method to find out which type of value it holds. The default constructor of QVariant creates an invalid value that you can detect using the isValid() method.

QVariant supports a great amount of types, including Qt value types such as QDateTime, QColor, and QPoint. You can also register your own types to store them in QVariant. One of the most powerful features of QVariant is the ability to store a collection or a hierarchy of values. ...

Get Game Programming using Qt 5 Beginner's Guide - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.