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. ...