QVariant var("Hello World"); const char* str = var.constData(); qDebug() << str; // output: "Hello World"
QVariant var(42); int val = *reinterpret_castIn this example, we create a QVariant containing an integer 42. We use constData() to get a const pointer to the integer data, and then reinterpret_cast it to a const int pointer. Finally, we dereference the pointer to get the integer value. Package library: Qt library(var.constData()); qDebug() << val; // output: 42