Q:

Is there an easy way of using the QVariant class with hexadecimal strings?

This code sample works as I would expect:
v = QVariant("123456");
qDebug() << v; // QVariant(QString, "123456")
v.convert(QVariant::Int);
qDebug() << v; // QVariant(int, 123456)
v.convert(QVariant::String);
qDebug() << v; // QVariant(QString, "123456")

Where as this doesn't:
v = QVariant("0xBEEF");
qDebug() << v; // QVariant(QString, "0xBEEF")
v.convert(QVariant::Int);
qDebug() << v; // QVariant(int, 0)
v.convert(QVariant::String);
qDebug() << v; // QVariant(QString, "")

Is there any simple way to make the QVariant class work with hexadecimal strings so the second example would work something like this:
v = QVariant("0xBEEF");
qDebug() << v; // QVariant(QString, "0xBEEF")
v.convert(QVariant::Int);
qDebug() << v; // QVariant(int, 48879)
v.convert(QVariant::String);
qDebug() << v; // QVariant(QString, "48879")

A:

When converting a qvariant to a numeric value you need to specify the base. Also make sure the value will fit in the int/long/longlong or then the conversion will fail for that reason instead.
QVariant v = QVariant("0xDEADBEAF");
bool test;
qDebug() << v.toString().toLongLong(&test,16);
qDebug() << test;

will produce the correct output
3735928495 
true 

while 
QVariant v = QVariant("0xDEADBEAF");
bool test;
qDebug() << v.toString().toInt(&test,16);
qDebug() << test;

will output 
0
false

