QVariant value = 42; QByteArray bytes = value.toByteArray();
QVariant value = "Hello, world!"; QByteArray bytes = value.toByteArray();In this example, a QVariant object is created with a string value of "Hello, world!". The toByteArray method is then called, which returns a QByteArray containing the string as bytes. These examples are part of the Qt library, specifically the QtCore module.