QVariant var(42); // store an integer value QString type = var.typeName(); // get the type name as a string qDebug() << type; // prints "int"
QVariant var("Hello, world!"); // store a string value QString type = var.typeName(); // get the type name as a string qDebug() << type; // prints "QString"In this example, a QVariant object is created that stores a string value. The typeName method is called on the QVariant object, and the resulting string is printed to the console. The output is "QString", which is the name of the Qt string type. This code is part of the Qt library package.