//creating a QVariant variable QVariant var; //setting the value of the variant var.setValue(5); //retrieving the value of the variant int x = var.toInt();
//creating a QVariantMap variable QVariantMap map; //setting values within the map map.insert("name", QVariant("John")); map.insert("age", QVariant(25)); //retrieving the values within the map QString name = map.value("name").toString(); int age = map.value("age").toInt();In this example, we are creating a `QVariantMap` named `map`, adding two key-value pairs to it (`name` and `age`) and retrieving their values. The QVariant class is part of the QtCore package library in Qt.