QVariant var1 = 3.14; // storing double value double d = var1.toDouble(); // converting to double cout << d; // output: 3.14
QVariant var2 = "42"; // storing string value double d = var2.toDouble(); // converting to double cout << d; // output: 42.0This code snippet stores a string value in a QVariant variable `var2`, then converts it to a double data type and prints its value to the console. Since the string can be converted to a double, the output is the double value of the string "42". The package library for QVariant is Qt Core.