QVariant var = "123"; if (var.canConvert()) { int value = var.toInt(); }
QVariant var = QDateTime::currentDateTime(); if (var.canConvertIn this example, a QVariant is created containing the current date and time using QDateTime::currentDateTime(). The canConvert function is used to check if this QVariant can be converted to a QString. Since the conversion is possible, the toString() function is called to get the string representation of the date and time. The QVariant class is part of the Qt Core library.()) { QString value = var.toString(); }